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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Mar 7, 2019 at 07:29 UTC 1366c78c239e7abb24d5b74cedf237f82125492d
2 files changed +9 -2
builtin/stash.c
+3 -2
@@ -830,7 +830,7 @@ static void add_pathspecs(struct argv_array *args,
830 int i;
831
832 for (i = 0; i < ps.nr; i++)
833 - argv_array_push(args, ps.items[i].match);
833 + argv_array_push(args, ps.items[i].original);
834 }
835
836 /*
@@ -1466,7 +1466,8 @@ static int push_stash(int argc, const char **argv, const char *prefix)
1466 git_stash_push_usage,
1467 0);
1468
1469 - parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL, prefix, argv);
1469 + parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL | PATHSPEC_PREFIX_ORIGIN,
1470 + prefix, argv);
1471 return do_push_stash(ps, stash_msg, quiet, keep_index, patch_mode,
1472 include_untracked);
1473 }
t/t3905-stash-include-untracked.sh
+6
@@ -283,4 +283,10 @@ test_expect_success 'stash -u -- <non-existant> shows no changes when there are
283 test_i18ncmp expect actual
284 '
285
286 +test_expect_success 'stash -u with globs' '
287 + >untracked.txt &&
288 + git stash -u -- ":(glob)**/*.txt" &&
289 + test_path_is_missing untracked.txt
290 +'
291 +
292 test_done