Skip to content

Commit dea96aa

Browse files
committed
Merge branch 'ow/stash-count-in-status-porcelain-output'
Allow "git status --porcelain=v2" to show the number of stash entries with --show-stash like the normal output does. * ow/stash-count-in-status-porcelain-output: status: print stash info with --porcelain=v2 --show-stash status: count stash entries in separate function
2 parents 96eca02 + 2e59e78 commit dea96aa

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

Documentation/git-status.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ Line Notes
314314
------------------------------------------------------------
315315
....
316316

317+
Stash Information
318+
^^^^^^^^^^^^^^^^^
319+
320+
If `--show-stash` is given, one line is printed showing the number of stash
321+
entries if non-zero:
322+
323+
# stash <N>
324+
317325
Changed Tracked Entries
318326
^^^^^^^^^^^^^^^^^^^^^^^
319327

t/t7064-wtstatus-pv2.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ test_expect_success 'after first commit, create unstaged changes' '
113113
test_cmp expect actual
114114
'
115115

116+
test_expect_success 'after first commit, stash existing changes' '
117+
cat >expect <<-EOF &&
118+
# branch.oid $H0
119+
# branch.head initial-branch
120+
# stash 2
121+
EOF
122+
123+
test_when_finished "git stash pop && git stash pop" &&
124+
125+
git stash -- file_x &&
126+
git stash &&
127+
git status --porcelain=v2 --branch --show-stash --untracked-files=no >actual &&
128+
test_cmp expect actual
129+
'
130+
116131
test_expect_success 'after first commit but omit untracked files and branch' '
117132
cat >expect <<-EOF &&
118133
1 .M N... 100644 100644 100644 $OID_X $OID_X file_x

wt-status.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,11 +948,17 @@ static int stash_count_refs(struct object_id *ooid, struct object_id *noid,
948948
return 0;
949949
}
950950

951+
static int count_stash_entries(void)
952+
{
953+
int n = 0;
954+
for_each_reflog_ent("refs/stash", stash_count_refs, &n);
955+
return n;
956+
}
957+
951958
static void wt_longstatus_print_stash_summary(struct wt_status *s)
952959
{
953-
int stash_count = 0;
960+
int stash_count = count_stash_entries();
954961

955-
for_each_reflog_ent("refs/stash", stash_count_refs, &stash_count);
956962
if (stash_count > 0)
957963
status_printf_ln(s, GIT_COLOR_NORMAL,
958964
Q_("Your stash currently has %d entry",
@@ -2176,6 +2182,18 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
21762182
}
21772183
}
21782184

2185+
/*
2186+
* Print the stash count in a porcelain-friendly format
2187+
*/
2188+
static void wt_porcelain_v2_print_stash(struct wt_status *s)
2189+
{
2190+
int stash_count = count_stash_entries();
2191+
char eol = s->null_termination ? '\0' : '\n';
2192+
2193+
if (stash_count > 0)
2194+
fprintf(s->fp, "# stash %d%c", stash_count, eol);
2195+
}
2196+
21792197
/*
21802198
* Convert various submodule status values into a
21812199
* fixed-length string of characters in the buffer provided.
@@ -2437,6 +2455,9 @@ static void wt_porcelain_v2_print(struct wt_status *s)
24372455
if (s->show_branch)
24382456
wt_porcelain_v2_print_tracking(s);
24392457

2458+
if (s->show_stash)
2459+
wt_porcelain_v2_print_stash(s);
2460+
24402461
for (i = 0; i < s->change.nr; i++) {
24412462
it = &(s->change.items[i]);
24422463
d = it->util;

0 commit comments

Comments
 (0)