Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cb76eed

Browse files
author
Edward Thomson
authored
Merge pull request libgit2#4054 from jfultz/jfultz/fix_GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH
Fix handling of GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH flag.
2 parents 2854e61 + 5f959dc commit cb76eed

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/checkout.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,6 +2553,10 @@ int git_checkout_iterator(
25532553
GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE;
25542554
baseline_opts.start = data.pfx;
25552555
baseline_opts.end = data.pfx;
2556+
if (opts && (opts->checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH)) {
2557+
baseline_opts.pathlist.count = opts->paths.count;
2558+
baseline_opts.pathlist.strings = opts->paths.strings;
2559+
}
25562560

25572561
if (data.opts.baseline_index) {
25582562
if ((error = git_iterator_for_index(

tests/checkout/tree.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,44 @@ void test_checkout_tree__can_checkout_with_pattern(void)
422422
cl_assert(git_path_exists("testrepo/new.txt"));
423423
}
424424

425+
void test_checkout_tree__pathlist_checkout_ignores_non_matches(void)
426+
{
427+
char *entries[] = { "branch_file.txt", "link_to_new.txt" };
428+
429+
/* reset to beginning of history (i.e. just a README file) */
430+
431+
g_opts.checkout_strategy =
432+
GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
433+
434+
cl_git_pass(git_revparse_single(&g_object, g_repo, "refs/heads/master"));
435+
436+
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
437+
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
438+
439+
cl_assert(git_path_exists("testrepo/README"));
440+
cl_assert(git_path_exists("testrepo/branch_file.txt"));
441+
cl_assert(git_path_exists("testrepo/link_to_new.txt"));
442+
cl_assert(git_path_exists("testrepo/new.txt"));
443+
444+
cl_git_pass(git_revparse_single(&g_object, g_repo, "8496071c1b46c854b31185ea97743be6a8774479"));
445+
446+
g_opts.checkout_strategy =
447+
GIT_CHECKOUT_FORCE | GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH;
448+
g_opts.paths.strings = entries;
449+
g_opts.paths.count = 2;
450+
451+
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
452+
453+
cl_assert(git_path_exists("testrepo/README"));
454+
cl_assert(!git_path_exists("testrepo/branch_file.txt"));
455+
cl_assert(!git_path_exists("testrepo/link_to_new.txt"));
456+
cl_assert(git_path_exists("testrepo/new.txt"));
457+
458+
git_object_free(g_object);
459+
g_object = NULL;
460+
461+
}
462+
425463
void test_checkout_tree__can_disable_pattern_match(void)
426464
{
427465
char *entries[] = { "b*.txt" };

0 commit comments

Comments
 (0)