Re: Git Status Short Output Color Inconsistency with -z Flag
- From
Jeff King <peff@peff.net>
- Date
- Oct 7, 2025, 08:29 UTC
- Message-ID
- <20251007082920.GA3349249@coredump.intra.peff.net>
- In-Reply-To
- <XCDlwEkTlgoZIyIf_8BfOGl1C3C63Ioxeib4BRNJ9Jm_CtYWKT3qu-pDaeXVtS1Ifq6E4pT9G0yDbIS_nSwN-uiBuBNAlMyrOv0R1RyM7oc=@protonmail.com>
On Sun, Oct 05, 2025 at 12:48:43AM +0000, Langbart wrote:
Show 13 quoted lines
> What did you do before the bug happened? (Steps to reproduce your issue) > > 1. Create an untracked file and modify an existing tracked file > 2. Run: git status --short -z > > What did you expect to happen? (Expected behavior) > > All status markers have colors disabled > > What happened instead? (Actual behavior) > > - Modified marker (`M`) appears colored > - Untracked marker (`??`) appears *uncolored*
There is a bug here, but I don't think your expectation matches the documentation. In the --short output, we do still respect color. We do not for the machine-readable --porcelain output, which is also implied by "-z" without another format.
So either of:
git status -z --porcelain
# this implies --porcelain=v1 git status -z
will do what you expected. Asking for "-z --short" is a bit unusual, since "--short" is meant to be human-readable and "-z" generally is not. So I'd expect it to be used only for relaying colorized information to a human over another channel or something.
But back to the bug. As you noticed, one item is colorized and the other is not. I think the fix is probably this:
diff --git a/wt-status.c b/wt-status.c index 8ffe6d3988..e12adb26b9 100644 --- a/wt-status.c +++ b/wt-status.c @@ -2042,13 +2042,13 @@ static void wt_shortstatus_status(struct string_list_item *it, static void wt_shortstatus_other(struct string_list_item *it, struct wt_status *s, const char *sign) { + color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign); if (s->null_termination) { - fprintf(s->fp, "%s %s%c", sign, it->string, 0); + fprintf(s->fp, " %s%c", it->string, 0); } else { struct strbuf onebuf = STRBUF_INIT; const char *one; one = quote_path(it->string, s->prefix, &onebuf, QUOTE_PATH_QUOTE_SP); - color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign); fprintf(s->fp, " %s\n", one); strbuf_release(&onebuf); } which matches how other output functions like wt_shortstatus_unmerged() behave (handling color before hitting the null_termination conditional). -Peff