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 <oystwa@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Øystein Walle committed
Oct 22, 2021 at 00:25 UTC
2e59e78096313920df470b6645a4323e2d8c0c6f
3 files changed
+38
Documentation/git-status.txt
+8
@@ -314,6 +314,14 @@ Line Notes
314
------------------------------------------------------------
315
....
316
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
+
325
Changed Tracked Entries
326
^^^^^^^^^^^^^^^^^^^^^^^
327
t/t7064-wtstatus-pv2.sh
+15
@@ -113,6 +113,21 @@ test_expect_success 'after first commit, create unstaged changes' '
113
test_cmp expect actual
114
'
115
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
+
131
test_expect_success 'after first commit but omit untracked files and branch' '
132
cat >expect <<-EOF &&
133
1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
wt-status.c
+15
@@ -2182,6 +2182,18 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
2182
}
2183
}
2184
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
+
2197
/*
2198
* Convert various submodule status values into a
2199
* fixed-length string of characters in the buffer provided.
@@ -2443,6 +2455,9 @@ static void wt_porcelain_v2_print(struct wt_status *s)
2455
if (s->show_branch)
2456
wt_porcelain_v2_print_tracking(s);
2457
2458
+ if (s->show_stash)
2459
+ wt_porcelain_v2_print_stash(s);
2460
+
2461
for (i = 0; i < s->change.nr; i++) {
2462
it = &(s->change.items[i]);
2463
d = it->util;