merge: work around write-side racy protection when hacking the index As we attempt to replicate a situation in which an older checkout has put a file on disk with different filtering settings from us, set the timestamp on the entry and file to a second before we're performing the operation so the entry in the index counts as old. This way we can test that we're not looking at the on-disk file when the index has the entry and we detect it as clean.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/tests/merge/workdir/dirty.c b/tests/merge/workdir/dirty.c
index 30c404b..4bf984c 100644
--- a/tests/merge/workdir/dirty.c
+++ b/tests/merge/workdir/dirty.c
@@ -133,12 +133,25 @@ static void hack_index(char *files[])
struct stat statbuf;
git_buf path = GIT_BUF_INIT;
git_index_entry *entry;
+ struct timeval times[2];
+ time_t now;
size_t i;
/* Update the index to suggest that checkout placed these files on
* disk, keeping the object id but updating the cache, which will
* emulate a Git implementation's different filter.
+ *
+ * We set the file's timestamp to before now to pretend that
+ * it was an old checkout so we don't trigger the racy
+ * protections would would check the content.
*/
+
+ now = time(NULL);
+ times[0].tv_sec = now - 5;
+ times[0].tv_usec = 0;
+ times[1].tv_sec = now - 5;
+ times[1].tv_usec = 0;
+
for (i = 0, filename = files[i]; filename; filename = files[++i]) {
git_buf_clear(&path);
@@ -146,6 +159,7 @@ static void hack_index(char *files[])
git_index_get_bypath(repo_index, filename, 0));
cl_git_pass(git_buf_printf(&path, "%s/%s", TEST_REPO_PATH, filename));
+ cl_git_pass(p_utimes(path.ptr, times));
cl_git_pass(p_stat(path.ptr, &statbuf));
entry->ctime.seconds = (git_time_t)statbuf.st_ctime;
@@ -245,7 +259,6 @@ static int merge_differently_filtered_files(char *files[])
write_files(files);
hack_index(files);
- repo_index->stamp.mtime = time(NULL) + 1;
cl_git_pass(git_index_write(repo_index));
error = merge_branch();