diff --git a/src/unix/posix.h b/src/unix/posix.h index 8b4f427f7..35bd431b8 100644 --- a/src/unix/posix.h +++ b/src/unix/posix.h @@ -26,6 +26,7 @@ typedef int GIT_SOCKET; #define p_mkdir(p,m) mkdir(p, m) #define p_fsync(fd) fsync(fd) extern char *p_realpath(const char *, char *); +#define p_utimensat(fd, path, times, flags) utimensat(fd, path, times, flags) #define p_recv(s,b,l,f) recv(s,b,l,f) #define p_send(s,b,l,f) send(s,b,l,f) diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c index 381b04013..e0d94e79f 100644 --- a/tests/checkout/crlf.c +++ b/tests/checkout/crlf.c @@ -4,6 +4,7 @@ #include "git2/checkout.h" #include "repository.h" +#include "index.h" #include "posix.h" static git_repository *g_repo; @@ -31,6 +32,25 @@ void test_checkout_crlf__detect_crlf_autocrlf_false(void) check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW); } +static void tick_index(git_index *index) +{ + git_time_t ts; + struct timespec times[2]; + + cl_assert(index->on_disk); + cl_assert(git_index_path(index)); + + cl_git_pass(git_index_read(index, true)); + ts = index->stamp.mtime; + + times[0].tv_sec = UTIME_OMIT; /* dont' change the atime */ + times[0].tv_nsec = UTIME_OMIT; /* dont' change the atime */ + times[1].tv_sec = ts + 1; + times[1].tv_nsec = 0; + cl_git_pass(p_utimensat(AT_FDCWD, git_index_path(index), times, 0)); + cl_git_pass(git_index_read(index, true)); +} + void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void) { git_index *index; @@ -40,9 +60,10 @@ void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void) cl_repo_set_bool(g_repo, "core.autocrlf", false); - git_checkout_head(g_repo, &opts); - git_repository_index(&index, g_repo); + tick_index(index); + + git_checkout_head(g_repo, &opts); cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL); cl_assert(entry->file_size == strlen(ALL_LF_TEXT_RAW)); @@ -140,9 +161,10 @@ void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void) cl_repo_set_bool(g_repo, "core.autocrlf", true); - git_checkout_head(g_repo, &opts); - git_repository_index(&index, g_repo); + tick_index(index); + + git_checkout_head(g_repo, &opts); cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);