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 <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff Hostetler committed
Aug 5, 2016 at 18:00 UTC
c4f596b98ed305ceb594857fa34524fedc30a031
3 files changed
+44
-5
Documentation/git-status.txt
+5
-2
@@ -32,11 +32,14 @@ OPTIONS
32
--branch::
33
Show the branch and tracking info even in short-format.
34
35
---porcelain::
35
+--porcelain[=<version>]::
36
Give the output in an easy-to-parse format for scripts.
37
This is similar to the short output, but will remain stable
38
across Git versions and regardless of user configuration. See
39
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.
43
44
--long::
45
Give the output in the long-format. This is the default.
@@ -96,7 +99,7 @@ configuration variable documented in linkgit:git-config[1].
99
100
-z::
101
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.
103
104
--column[=<options>]::
105
--no-column::
builtin/commit.c
+18
-3
@@ -144,6 +144,21 @@ static struct strbuf message = STRBUF_INIT;
144
145
static enum wt_status_format status_format = STATUS_FORMAT_UNSPECIFIED;
146
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
+
162
static int opt_parse_m(const struct option *opt, const char *arg, int unset)
163
{
164
struct strbuf *buf = opt->value;
@@ -1316,9 +1331,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1331
N_("show status concisely"), STATUS_FORMAT_SHORT),
1332
OPT_BOOL('b', "branch", &s.show_branch,
1333
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 },
1337
OPT_SET_INT(0, "long", &status_format,
1338
N_("show status in long format (default)"),
1339
STATUS_FORMAT_LONG),
t/t7060-wtstatus.sh
+21
@@ -228,4 +228,25 @@ test_expect_success 'status --branch with detached HEAD' '
228
test_i18ncmp expected actual
229
'
230
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
+
252
test_done