Skip to content

Commit 1366c78

Browse files
dschogitster
authored andcommitted
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7b556aa commit 1366c78

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
@@ -830,7 +830,7 @@ static void add_pathspecs(struct argv_array *args,
830830
int i;
831831

832832
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);
834834
}
835835

836836
/*
@@ -1466,7 +1466,8 @@ static int push_stash(int argc, const char **argv, const char *prefix)
14661466
git_stash_push_usage,
14671467
0);
14681468

1469-
parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL, prefix, argv);
1469+
parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL | PATHSPEC_PREFIX_ORIGIN,
1470+
prefix, argv);
14701471
return do_push_stash(ps, stash_msg, quiet, keep_index, patch_mode,
14711472
include_untracked);
14721473
}

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)