From 877c51ee1bbd6e70ff78a425781400d94a49a168 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 7 Mar 2019 15:04:10 +0100 Subject: [PATCH] built-in stash: handle :(glob) pathspecs again When passing a list of pathspecs to, say, `git add`, we need to be careful to use the original form, not the parsed form of the pathspecs. This makes a difference e.g. when calling git stash -- ':(glob)**/*.txt' where the original form includes the `:(glob)` prefix while the parsed form does not. However, in the built-in `git stash`, we passed the parsed (i.e. incorrect) form, and `git add` would fail with the error message: fatal: pathspec '**/*.txt' did not match any files at the stage where `git stash` drops the changes from the worktree, even if `refs/stash` has been actually updated successfully. This fixes https://github.com/git-for-windows/git/issues/2037 Signed-off-by: Johannes Schindelin --- builtin/stash.c | 5 +++-- t/t3905-stash-include-untracked.sh | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/builtin/stash.c b/builtin/stash.c index 51df0926331907..f7428b08f5ac75 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -832,7 +832,7 @@ static void add_pathspecs(struct argv_array *args, int i; for (i = 0; i < ps.nr; i++) - argv_array_push(args, ps.items[i].match); + argv_array_push(args, ps.items[i].original); } /* @@ -1468,7 +1468,8 @@ static int push_stash(int argc, const char **argv, const char *prefix) git_stash_push_usage, 0); - parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL, prefix, argv); + parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL | PATHSPEC_PREFIX_ORIGIN, + prefix, argv); return do_push_stash(ps, stash_msg, quiet, keep_index, patch_mode, include_untracked); } diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh index cc1c8a7bb2da50..29ca76f2fbea92 100755 --- a/t/t3905-stash-include-untracked.sh +++ b/t/t3905-stash-include-untracked.sh @@ -283,4 +283,10 @@ test_expect_success 'stash -u -- shows no changes when there are test_i18ncmp expect actual ' +test_expect_success 'stash -u with globs' ' + >untracked.txt && + git stash -u -- ":(glob)**/*.txt" && + test_path_is_missing untracked.txt +' + test_done