summaryrefslogtreecommitdiff
path: root/tests/checkout
diff options
context:
space:
mode:
authorJohn Fultz <jfultz@wolfram.com>2016-12-29 19:26:50 -0600
committerJohn Fultz <jfultz@wolfram.com>2016-12-29 20:13:03 -0600
commit5f959dca0d7d7d921ccf2948e0745659f6055148 (patch)
tree0e8f1b4d893f62332172b2ef5c72dd360bdc272a /tests/checkout
parent238b8ccd1aeec0e0d6e50c5050527a8107304bfb (diff)
downloadlibgit2-5f959dca0d7d7d921ccf2948e0745659f6055148.tar.gz
Fix handling of GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH flag.
git_checkout_tree() sets up its working directory iterator to respect the pathlist if GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH is present, which is great. What's not so great is that this iterator is then used side-by-side with an iterator created by git_checkout_iterator(), which did not set up its pathlist appropriately (although the iterator mirrors all other iterator options). This could cause git_checkout_tree() to delete working tree files which were not specified in the pathlist when GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH was used, as the unsynchronized iterators causes git_checkout_tree() to think that files have been deleted between the two trees. Oops. And added a test which fails without this fix (specifically, the final check for "testrepo/README" to still be present fails).
Diffstat (limited to 'tests/checkout')
-rw-r--r--tests/checkout/tree.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c
index 4a0314a9e..c9581fdc5 100644
--- a/tests/checkout/tree.c
+++ b/tests/checkout/tree.c
@@ -422,6 +422,44 @@ void test_checkout_tree__can_checkout_with_pattern(void)
cl_assert(git_path_exists("testrepo/new.txt"));
}
+void test_checkout_tree__pathlist_checkout_ignores_non_matches(void)
+{
+ char *entries[] = { "branch_file.txt", "link_to_new.txt" };
+
+ /* reset to beginning of history (i.e. just a README file) */
+
+ g_opts.checkout_strategy =
+ GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
+
+ cl_git_pass(git_revparse_single(&g_object, g_repo, "refs/heads/master"));
+
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
+
+ cl_assert(git_path_exists("testrepo/README"));
+ cl_assert(git_path_exists("testrepo/branch_file.txt"));
+ cl_assert(git_path_exists("testrepo/link_to_new.txt"));
+ cl_assert(git_path_exists("testrepo/new.txt"));
+
+ cl_git_pass(git_revparse_single(&g_object, g_repo, "8496071c1b46c854b31185ea97743be6a8774479"));
+
+ g_opts.checkout_strategy =
+ GIT_CHECKOUT_FORCE | GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH;
+ g_opts.paths.strings = entries;
+ g_opts.paths.count = 2;
+
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+
+ cl_assert(git_path_exists("testrepo/README"));
+ cl_assert(!git_path_exists("testrepo/branch_file.txt"));
+ cl_assert(!git_path_exists("testrepo/link_to_new.txt"));
+ cl_assert(git_path_exists("testrepo/new.txt"));
+
+ git_object_free(g_object);
+ g_object = NULL;
+
+}
+
void test_checkout_tree__can_disable_pattern_match(void)
{
char *entries[] = { "b*.txt" };