summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSegev Finer <segev@codeocean.com>2019-06-03 18:35:08 +0300
committerEdward Thomson <ethomson@edwardthomson.com>2020-05-11 00:15:06 +0100
commitd62e44cb8218840a0291fb5fbb7c5106e1e35a12 (patch)
treed46e7faea4ce7774eb4094a7bc55ceb2c31971ef /tests
parent2a1d97e6e7ca0fee3fcc5e86e8bf61ab2f182d64 (diff)
downloadlibgit2-d62e44cb8218840a0291fb5fbb7c5106e1e35a12.tar.gz
checkout: Fix removing untracked files by path in subdirectories
The checkout code didn't iterate into a subdir if it didn't match the pathspec, but since the pathspec might match files in the subdir we should recurse into it (In contrast to gitignore handling). Fixes #5089
Diffstat (limited to 'tests')
-rw-r--r--tests/checkout/head.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/checkout/head.c b/tests/checkout/head.c
index 799123086..5b3a034e7 100644
--- a/tests/checkout/head.c
+++ b/tests/checkout/head.c
@@ -109,6 +109,32 @@ void test_checkout_head__do_not_remove_untracked_file_in_subdir(void)
cl_assert(git_path_isfile("testrepo/tracked/subdir/untracked"));
}
+void test_checkout_head__do_remove_untracked_paths(void)
+{
+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
+ git_index *index;
+ char *paths[] = {"tracked/untracked"};
+
+ cl_git_pass(p_mkdir("testrepo/tracked", 0755));
+ cl_git_pass(p_mkdir("testrepo/tracked/subdir", 0755));
+ cl_git_mkfile("testrepo/tracked/tracked", "tracked\n");
+ cl_git_mkfile("testrepo/tracked/untracked", "untracked\n");
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_index_add_bypath(index, "tracked/tracked"));
+ cl_git_pass(git_index_write(index));
+
+ git_index_free(index);
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
+ opts.paths.strings = paths;
+ opts.paths.count = 1;
+ cl_git_pass(git_checkout_head(g_repo, &opts));
+
+ cl_assert(git_path_isfile("testrepo/tracked/tracked"));
+ cl_assert(!git_path_isfile("testrepo/tracked/untracked"));
+}
+
void test_checkout_head__do_remove_tracked_subdir(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;