Skip to content

Commit 66af0b6

Browse files
committed
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 #2037 Signed-off-by: Johannes Schindelin <[email protected]>
1 parent ab15e05 commit 66af0b6

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

builtin/stash.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ static void add_pathspecs(struct argv_array *args,
832832
int i;
833833

834834
for (i = 0; i < ps.nr; i++)
835-
argv_array_push(args, ps.items[i].match);
835+
argv_array_push(args, ps.items[i].original);
836836
}
837837

838838
/*
@@ -1468,7 +1468,8 @@ static int push_stash(int argc, const char **argv, const char *prefix)
14681468
git_stash_push_usage,
14691469
0);
14701470

1471-
parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL, prefix, argv);
1471+
parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL | PATHSPEC_PREFIX_ORIGIN,
1472+
prefix, argv);
14721473
return do_push_stash(ps, stash_msg, quiet, keep_index, patch_mode,
14731474
include_untracked);
14741475
}

t/t3905-stash-include-untracked.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,10 @@ test_expect_success 'stash -u -- <non-existant> shows no changes when there are
283283
test_i18ncmp expect actual
284284
'
285285

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+
286292
test_done

0 commit comments

Comments
 (0)