Commit 275693e29cc90024bb21716a4943b8e64cd5d16d

Edward Thomson 2018-02-20T12:45:40

checkout test: ensure workdir mode is simplified Ensure that when examining the working directory for checkout that the mode is correctly simplified. Git only pays attention to whether a file is executable or not. When examining a working directory, we should coalesce modes in the working directory to either `0755` (indicating that a file is executable) or `0644` (indicating that it is not). Test this by giving the file an exotic mode, and ensuring that when checkout out a branch that changes the file's contents, that we do not have a checkout conflict.

diff --git a/tests/checkout/head.c b/tests/checkout/head.c
index 866eb9a..9906146 100644
--- a/tests/checkout/head.c
+++ b/tests/checkout/head.c
@@ -182,6 +182,33 @@ void test_checkout_head__typechange_index_and_workdir(void)
 	git_index_free(index);
 }
 
+void test_checkout_head__workdir_filemode_is_simplified(void)
+{
+	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
+	git_object *target, *branch;
+
+	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+
+	cl_git_pass(git_revparse_single(&target, g_repo, "a38d028f71eaa590febb7d716b1ca32350cf70da"));
+	cl_git_pass(git_reset(g_repo, target, GIT_RESET_HARD, NULL));
+
+	cl_must_pass(p_chmod("testrepo/branch_file.txt", 0666));
+
+	/*
+	 * Checkout should not fail with a conflict; though the file mode
+	 * on disk is literally different to the base (0666 vs 0644), Git
+	 * ignores the actual mode and simply treats both as non-executable.
+	 */
+	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);
+}
+
 void test_checkout_head__obeys_filemode_true(void)
 {
 	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;