diff options
| author | Carlos Martín Nieto <cmn@dwim.me> | 2015-06-20 13:17:06 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-06-22 16:11:58 +0200 |
| commit | 5b05f954242a00077eedcdff8f20a820299deef2 (patch) | |
| tree | 520198fff318def2c7e3885b57945123304a9035 | |
| parent | 26432a9c62957957bfca96634de6b1e77052c1c5 (diff) | |
| download | libgit2-5b05f954242a00077eedcdff8f20a820299deef2.tar.gz | |
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.
| -rw-r--r-- | tests/merge/workdir/dirty.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/merge/workdir/dirty.c b/tests/merge/workdir/dirty.c index 30c404b70..4bf984c23 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(); |
