Skip to content

Commit ee2e630

Browse files
committed
Merge branch 'tg/stash-ref-by-index-fix' into next
"git stash show 23" used to work, but no more after getting rewritten in C; this regression has been corrected. * tg/stash-ref-by-index-fix: stash: fix show referencing stash index
2 parents df44db4 + 63b50c8 commit ee2e630

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

builtin/stash.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,11 +713,11 @@ static int git_stash_config(const char *var, const char *value, void *cb)
713713
static int show_stash(int argc, const char **argv, const char *prefix)
714714
{
715715
int i;
716-
int opts = 0;
717716
int ret = 0;
718717
struct stash_info info;
719718
struct rev_info rev;
720719
struct argv_array stash_args = ARGV_ARRAY_INIT;
720+
struct argv_array revision_args = ARGV_ARRAY_INIT;
721721
struct option options[] = {
722722
OPT_END()
723723
};
@@ -726,11 +726,12 @@ static int show_stash(int argc, const char **argv, const char *prefix)
726726
git_config(git_diff_ui_config, NULL);
727727
init_revisions(&rev, prefix);
728728

729+
argv_array_push(&revision_args, argv[0]);
729730
for (i = 1; i < argc; i++) {
730731
if (argv[i][0] != '-')
731732
argv_array_push(&stash_args, argv[i]);
732733
else
733-
opts++;
734+
argv_array_push(&revision_args, argv[i]);
734735
}
735736

736737
ret = get_stash_info(&info, stash_args.argc, stash_args.argv);
@@ -742,7 +743,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
742743
* The config settings are applied only if there are not passed
743744
* any options.
744745
*/
745-
if (!opts) {
746+
if (revision_args.argc == 1) {
746747
git_config(git_stash_config, NULL);
747748
if (show_stat)
748749
rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT;
@@ -756,7 +757,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
756757
}
757758
}
758759

759-
argc = setup_revisions(argc, argv, &rev, NULL);
760+
argc = setup_revisions(revision_args.argc, revision_args.argv, &rev, NULL);
760761
if (argc > 1) {
761762
free_stash_info(&info);
762763
usage_with_options(git_stash_show_usage, options);

t/t3903-stash.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,24 @@ test_expect_success 'invalid ref of the form "n", n >= N' '
708708
git stash drop
709709
'
710710

711+
test_expect_success 'valid ref of the form "n", n < N' '
712+
git stash clear &&
713+
echo bar5 >file &&
714+
echo bar6 >file2 &&
715+
git add file2 &&
716+
git stash &&
717+
git stash show 0 &&
718+
git stash branch tmp 0 &&
719+
git checkout master &&
720+
git stash &&
721+
git stash apply 0 &&
722+
git reset --hard &&
723+
git stash pop 0 &&
724+
git stash &&
725+
git stash drop 0 &&
726+
test_must_fail git stash drop
727+
'
728+
711729
test_expect_success 'branch: do not drop the stash if the branch exists' '
712730
git stash clear &&
713731
echo foo >file &&

0 commit comments

Comments
 (0)