checkout test: add core.filemode checkout tests Add two tests for filemode. The first ensures that `core.filemode=true` is honored: if we have changed the filemode such that a file that _was_ executable (mode 0755) is now executable (mode 0644) and we go to check out a branch that has otherwise changed the contents of the file, then we should raise a checkout conflict for that file. The second ensures that `core.filemode=false` is honored: in the same situation, we set a file that was executable to be non-executable, and check out the branch that changes the contents of the file. However, since `core.filemode` is false, we do not detect the filemode change. We run these tests on both operating systems that obey `core.filemode` (eg, POSIX) and those that have no conception of filemode (eg, Win32). This ensures that `core.filemode` is always honored, as it is a cache of the underlying filesystem's settings. This ensures that we do not make assumptions based on the operating system, and honor the configuration setting even if it were misconfigured.
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/tests/checkout/head.c b/tests/checkout/head.c
index 46b2257..866eb9a 100644
--- a/tests/checkout/head.c
+++ b/tests/checkout/head.c
@@ -181,3 +181,59 @@ void test_checkout_head__typechange_index_and_workdir(void)
git_object_free(target);
git_index_free(index);
}
+
+void test_checkout_head__obeys_filemode_true(void)
+{
+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
+ git_object *target, *branch;
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+
+ /* In this commit, `README` is executable */
+ cl_git_pass(git_revparse_single(&target, g_repo, "f9ed4af42472941da45a3c"));
+ cl_git_pass(git_reset(g_repo, target, GIT_RESET_HARD, NULL));
+
+ cl_repo_set_bool(g_repo, "core.filemode", true);
+ cl_must_pass(p_chmod("testrepo/README", 0644));
+
+ /*
+ * Checkout will fail with a conflict; the file mode is updated in
+ * the checkout target, but the contents have changed in our branch.
+ */
+ cl_git_pass(git_revparse_single(&branch, g_repo, "099fabac3a9ea935598528c27f866e34089c2eff"));
+
+ opts.checkout_strategy &= ~GIT_CHECKOUT_FORCE;
+ opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
+ cl_git_fail_with(GIT_ECONFLICT, git_checkout_tree(g_repo, branch, NULL));
+
+ git_object_free(branch);
+ git_object_free(target);
+}
+
+void test_checkout_head__obeys_filemode_false(void)
+{
+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
+ git_object *target, *branch;
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+
+ /* In this commit, `README` is executable */
+ cl_git_pass(git_revparse_single(&target, g_repo, "f9ed4af42472941da45a3c"));
+ cl_git_pass(git_reset(g_repo, target, GIT_RESET_HARD, NULL));
+
+ cl_repo_set_bool(g_repo, "core.filemode", false);
+ cl_must_pass(p_chmod("testrepo/README", 0644));
+
+ /*
+ * Checkout will fail with a conflict; the file contents are updated
+ * in the checkout target, but the filemode has changed in our branch.
+ */
+ cl_git_pass(git_revparse_single(&branch, g_repo, "099fabac3a9ea935598528c27f866e34089c2eff"));
+
+ opts.checkout_strategy &= ~GIT_CHECKOUT_FORCE;
+ opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
+ cl_git_pass(git_checkout_tree(g_repo, branch, NULL));
+
+ git_object_free(branch);
+ git_object_free(target);
+}