Skip to content

Commit c7dad95

Browse files
jeffhostetlerdscho
authored andcommitted
status: support --porcelain[=<version>]
Update --porcelain argument to take optional version parameter to allow multiple porcelain formats to be supported in the future. The token "v1" is the default value and indicates the traditional porcelain format. (The token "1" is an alias for that.) Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5d708ba commit c7dad95

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

Documentation/git-status.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ OPTIONS
3232
--branch::
3333
Show the branch and tracking info even in short-format.
3434

35-
--porcelain::
35+
--porcelain[=<version>]::
3636
Give the output in an easy-to-parse format for scripts.
3737
This is similar to the short output, but will remain stable
3838
across Git versions and regardless of user configuration. See
3939
below for details.
40+
+
41+
The version parameter is used to specify the format version.
42+
This is optional and defaults to the original version 'v1' format.
4043

4144
--long::
4245
Give the output in the long-format. This is the default.
@@ -96,7 +99,7 @@ configuration variable documented in linkgit:git-config[1].
9699

97100
-z::
98101
Terminate entries with NUL, instead of LF. This implies
99-
the `--porcelain` output format if no other format is given.
102+
the `--porcelain=v1` output format if no other format is given.
100103

101104
--column[=<options>]::
102105
--no-column::

builtin/commit.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,21 @@ static struct strbuf message = STRBUF_INIT;
144144

145145
static enum wt_status_format status_format = STATUS_FORMAT_UNSPECIFIED;
146146

147+
static int opt_parse_porcelain(const struct option *opt, const char *arg, int unset)
148+
{
149+
enum wt_status_format *value = (enum wt_status_format *)opt->value;
150+
if (unset)
151+
*value = STATUS_FORMAT_NONE;
152+
else if (!arg)
153+
*value = STATUS_FORMAT_PORCELAIN;
154+
else if (!strcmp(arg, "v1") || !strcmp(arg, "1"))
155+
*value = STATUS_FORMAT_PORCELAIN;
156+
else
157+
die("unsupported porcelain version '%s'", arg);
158+
159+
return 0;
160+
}
161+
147162
static int opt_parse_m(const struct option *opt, const char *arg, int unset)
148163
{
149164
struct strbuf *buf = opt->value;
@@ -1316,9 +1331,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13161331
N_("show status concisely"), STATUS_FORMAT_SHORT),
13171332
OPT_BOOL('b', "branch", &s.show_branch,
13181333
N_("show branch information")),
1319-
OPT_SET_INT(0, "porcelain", &status_format,
1320-
N_("machine-readable output"),
1321-
STATUS_FORMAT_PORCELAIN),
1334+
{ OPTION_CALLBACK, 0, "porcelain", &status_format,
1335+
N_("version"), N_("machine-readable output"),
1336+
PARSE_OPT_OPTARG, opt_parse_porcelain },
13221337
OPT_SET_INT(0, "long", &status_format,
13231338
N_("show status in long format (default)"),
13241339
STATUS_FORMAT_LONG),

t/t7060-wtstatus.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,25 @@ test_expect_success 'status --branch with detached HEAD' '
232232
test_i18ncmp expected actual
233233
'
234234

235+
## Duplicate the above test and verify --porcelain=v1 arg parsing.
236+
test_expect_success 'status --porcelain=v1 --branch with detached HEAD' '
237+
git reset --hard &&
238+
git checkout master^0 &&
239+
git status --branch --porcelain=v1 >actual &&
240+
cat >expected <<-EOF &&
241+
## HEAD (no branch)
242+
?? .gitconfig
243+
?? actual
244+
?? expect
245+
?? expected
246+
?? mdconflict/
247+
EOF
248+
test_i18ncmp expected actual
249+
'
250+
251+
## Verify parser error on invalid --porcelain argument.
252+
test_expect_success 'status --porcelain=bogus' '
253+
test_must_fail git status --porcelain=bogus
254+
'
255+
235256
test_done

0 commit comments

Comments
 (0)