summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/checkout/checkout_helpers.c20
-rw-r--r--tests/checkout/checkout_helpers.h2
-rw-r--r--tests/checkout/crlf.c19
-rw-r--r--tests/diff/workdir.c6
-rw-r--r--tests/status/worktree.c6
5 files changed, 34 insertions, 19 deletions
diff --git a/tests/checkout/checkout_helpers.c b/tests/checkout/checkout_helpers.c
index 06b4e0682..c2e65b885 100644
--- a/tests/checkout/checkout_helpers.c
+++ b/tests/checkout/checkout_helpers.c
@@ -2,6 +2,7 @@
#include "checkout_helpers.h"
#include "refs.h"
#include "fileops.h"
+#include "index.h"
void assert_on_branch(git_repository *repo, const char *branch)
{
@@ -128,3 +129,22 @@ int checkout_count_callback(
return 0;
}
+
+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));
+}
diff --git a/tests/checkout/checkout_helpers.h b/tests/checkout/checkout_helpers.h
index 705ee903d..6058a196c 100644
--- a/tests/checkout/checkout_helpers.h
+++ b/tests/checkout/checkout_helpers.h
@@ -27,3 +27,5 @@ extern int checkout_count_callback(
const git_diff_file *target,
const git_diff_file *workdir,
void *payload);
+
+extern void tick_index(git_index *index);
diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c
index e0d94e79f..61459b3a4 100644
--- a/tests/checkout/crlf.c
+++ b/tests/checkout/crlf.c
@@ -32,25 +32,6 @@ 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;
diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c
index 5d6ebed95..6b72f3286 100644
--- a/tests/diff/workdir.c
+++ b/tests/diff/workdir.c
@@ -2,6 +2,7 @@
#include "diff_helpers.h"
#include "repository.h"
#include "git2/sys/diff.h"
+#include "../checkout/checkout_helpers.h"
static git_repository *g_repo = NULL;
@@ -1583,6 +1584,7 @@ void test_diff_workdir__can_update_index(void)
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff *diff = NULL;
git_diff_perfdata perf = GIT_DIFF_PERFDATA_INIT;
+ git_index *index;
g_repo = cl_git_sandbox_init("status");
@@ -1607,6 +1609,10 @@ void test_diff_workdir__can_update_index(void)
/* now allow diff to update stat cache */
opts.flags |= GIT_DIFF_UPDATE_INDEX;
+ /* advance a tick for the index so we don't re-calculate racily-clean entries */
+ cl_git_pass(git_repository_index__weakptr(&index, g_repo));
+ tick_index(index);
+
basic_diff_status(&diff, &opts);
cl_git_pass(git_diff_get_perfdata(&perf, diff));
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index 3b18ae6c0..f8d1f7f54 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -6,6 +6,7 @@
#include "util.h"
#include "path.h"
#include "../diff/diff_helpers.h"
+#include "../checkout/checkout_helpers.h"
#include "git2/sys/diff.h"
/**
@@ -956,6 +957,7 @@ void test_status_worktree__update_stat_cache_0(void)
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
git_status_list *status;
git_diff_perfdata perf = GIT_DIFF_PERFDATA_INIT;
+ git_index *index;
opts.flags = GIT_STATUS_OPT_DEFAULTS;
@@ -967,6 +969,10 @@ void test_status_worktree__update_stat_cache_0(void)
git_status_list_free(status);
+ /* tick the index so we avoid recalculating racily-clean entries */
+ cl_git_pass(git_repository_index__weakptr(&index, repo));
+ tick_index(index);
+
opts.flags |= GIT_STATUS_OPT_UPDATE_INDEX;
cl_git_pass(git_status_list_new(&status, repo, &opts));