Skip to content

Commit 6872353

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 999dce9 commit 6872353

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
@@ -228,4 +228,25 @@ test_expect_success 'status --branch with detached HEAD' '
228228
test_i18ncmp expected actual
229229
'
230230

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

0 commit comments

Comments
 (0)