Skip to content

Commit 2e59e78

Browse files
Ossegitster
authored andcommitted
status: print stash info with --porcelain=v2 --show-stash
The v2 porcelain format is very convenient for obtaining a lot of information about the current state of the repo, but does not contain any info about the stash. git status already accepts --show-stash but it's silently ignored when --porcelain=v2 is given. Let's add a simple line to print the number of stash entries but in a format similar in style to the rest of the format. Signed-off-by: Øystein Walle <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 612942a commit 2e59e78

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,18 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
21822182
}
21832183
}
21842184

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+
21852197
/*
21862198
* Convert various submodule status values into a
21872199
* fixed-length string of characters in the buffer provided.
@@ -2443,6 +2455,9 @@ static void wt_porcelain_v2_print(struct wt_status *s)
24432455
if (s->show_branch)
24442456
wt_porcelain_v2_print_tracking(s);
24452457

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

0 commit comments

Comments
 (0)