Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-06-15 15:32:08 +0300
committerCarlos Martín Nieto <cmn@dwim.me>2015-06-16 09:40:45 +0300
commitc4e6ab5f23819c35dc0c1a0fd7f50e5a194f0d5a (patch)
treefb858ad324aa607a9a81013c0a4066518361ba06 /tests/checkout
parent316b820b6fed712d4b6fae886ba1e6c44afc6c81 (diff)
crlf: tick the index forward to work around racy-git behaviour
In order to avoid racy-git, we zero out the file size for entries with the same timestamp as the index (or during the initial checkout). This is the case in a couple of crlf tests, as the code is fast enough to do everything in the same second. As we know that we do not perform the modification just after writing out the index, which is what this is designed to work around, tick the mtime of the index file such that it doesn't agree with the files anymore, and we do not zero out these entries.
Diffstat (limited to 'tests/checkout')
-rw-r--r--tests/checkout/crlf.c30
1 files changed, 26 insertions, 4 deletions
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);