]> git.ipfire.org Git - thirdparty/git.git/commitdiff
status: print stash info with --porcelain=v2 --show-stash
authorØystein Walle <oystwa@gmail.com>
Thu, 21 Oct 2021 22:25:32 +0000 (00:25 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 22 Oct 2021 00:24:30 +0000 (17:24 -0700)
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>
Documentation/git-status.txt
t/t7064-wtstatus-pv2.sh
wt-status.c

index 4a2c3e04081e27dd7cace80c3b63ab2cec843750..54a4b29b473cc4e928b484286b01b337c9b25bdd 100644 (file)
@@ -314,6 +314,14 @@ Line                                     Notes
 ------------------------------------------------------------
 ....
 
+Stash Information
+^^^^^^^^^^^^^^^^^
+
+If `--show-stash` is given, one line is printed showing the number of stash
+entries if non-zero:
+
+    # stash <N>
+
 Changed Tracked Entries
 ^^^^^^^^^^^^^^^^^^^^^^^
 
index eeb0534163db176442d38d19d0afb186cd985666..47fc21d96232ae4ae46e2e7a9db63723bdc66ff0 100755 (executable)
@@ -113,6 +113,21 @@ test_expect_success 'after first commit, create unstaged changes' '
        test_cmp expect actual
 '
 
+test_expect_success 'after first commit, stash existing changes' '
+       cat >expect <<-EOF &&
+       # branch.oid $H0
+       # branch.head initial-branch
+       # stash 2
+       EOF
+
+       test_when_finished "git stash pop && git stash pop" &&
+
+       git stash -- file_x &&
+       git stash &&
+       git status --porcelain=v2 --branch --show-stash --untracked-files=no >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'after first commit but omit untracked files and branch' '
        cat >expect <<-EOF &&
        1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
index 6c3edcdb45956f878bd2dc19e688fb3d8954834d..5d215f4e4f1ea862a169bab5c2cb2039ad0d50d3 100644 (file)
@@ -2182,6 +2182,18 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
        }
 }
 
+/*
+ * Print the stash count in a porcelain-friendly format
+ */
+static void wt_porcelain_v2_print_stash(struct wt_status *s)
+{
+       int stash_count = count_stash_entries();
+       char eol = s->null_termination ? '\0' : '\n';
+
+       if (stash_count > 0)
+               fprintf(s->fp, "# stash %d%c", stash_count, eol);
+}
+
 /*
  * Convert various submodule status values into a
  * fixed-length string of characters in the buffer provided.
@@ -2443,6 +2455,9 @@ static void wt_porcelain_v2_print(struct wt_status *s)
        if (s->show_branch)
                wt_porcelain_v2_print_tracking(s);
 
+       if (s->show_stash)
+               wt_porcelain_v2_print_stash(s);
+
        for (i = 0; i < s->change.nr; i++) {
                it = &(s->change.items[i]);
                d = it->util;