diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2018-02-20 12:45:40 +0000 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2018-02-23 16:54:39 -0800 |
commit | 275693e29cc90024bb21716a4943b8e64cd5d16d (patch) | |
tree | 888926d0c2daf714f1d17ff8576cf3e8ac79714b | |
parent | ec96db577922712f88e0b67cd2149de1f345bbbb (diff) | |
download | libgit2-275693e29cc90024bb21716a4943b8e64cd5d16d.tar.gz |
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.
-rw-r--r-- | tests/checkout/head.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/checkout/head.c b/tests/checkout/head.c index 866eb9a0b..99061466f 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; |