diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2018-02-20 00:32:38 +0000 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2018-02-23 16:54:39 -0800 |
commit | ec96db577922712f88e0b67cd2149de1f345bbbb (patch) | |
tree | 0df4b5fa51c9b97ba83f9e3270f69c2f48a1d4e5 | |
parent | 18d9c8479f8534cc19765345560d2d39b8920a4d (diff) | |
download | libgit2-ec96db577922712f88e0b67cd2149de1f345bbbb.tar.gz |
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.
-rw-r--r-- | tests/checkout/head.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/checkout/head.c b/tests/checkout/head.c index 46b22570d..866eb9a0b 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); +} |