Commit ec96db57 by Edward Thomson

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.
parent 18d9c847
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment