Skip to content

Commit

Permalink
Merge pull request #4054 from jfultz/jfultz/fix_GIT_CHECKOUT_DISABLE_…
Browse files Browse the repository at this point in the history
…PATHSPEC_MATCH

Fix handling of GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH flag.
  • Loading branch information
Edward Thomson committed Jan 14, 2017
2 parents 2854e61 + 5f959dc commit cb76eed
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,10 @@ int git_checkout_iterator(
GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE;
baseline_opts.start = data.pfx;
baseline_opts.end = data.pfx;
if (opts && (opts->checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH)) {
baseline_opts.pathlist.count = opts->paths.count;
baseline_opts.pathlist.strings = opts->paths.strings;
}

if (data.opts.baseline_index) {
if ((error = git_iterator_for_index(
Expand Down
38 changes: 38 additions & 0 deletions tests/checkout/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down

0 comments on commit cb76eed

Please sign in to comment.