Skip to content

Commit 7c9f703

Browse files
peffgitster
authored andcommitted
commit: support alternate status formats
The status command recently grew "short" and "porcelain" options for alternate output formats. Since status is no longer "commit --dry-run", these formats are inaccessible to people who do want to see a dry-run in a parseable form. This patch makes those formats available to "git commit", implying the "dry-run" option when they are used. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6f15787 commit 7c9f703

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

Documentation/git-commit.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ OPTIONS
7575
and paths that are untracked, similar to the one that is given
7676
in the commit log editor.
7777

78+
--short::
79+
When doing a dry-run, give the output in the short-format. See
80+
linkgit:git-status[1] for details. Implies `--dry-run`.
81+
82+
--porcelain::
83+
When doing a dry-run, give the output in a porcelain-ready
84+
format. See linkgit:git-status[1] for details. Implies
85+
`--dry-run`.
86+
87+
-z::
88+
When showing `short` or `porcelain` status output, terminate
89+
entries in the status output with NUL, instead of LF. If no
90+
format is given, implies the `--porcelain` output format.
91+
7892
-F <file>::
7993
--file=<file>::
8094
Take the commit message from the given file. Use '-' to

builtin-commit.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ static int use_editor = 1, initial_commit, in_merge;
7272
static const char *only_include_assumed;
7373
static struct strbuf message;
7474

75+
static int null_termination;
76+
static enum {
77+
STATUS_FORMAT_LONG,
78+
STATUS_FORMAT_SHORT,
79+
STATUS_FORMAT_PORCELAIN,
80+
} status_format = STATUS_FORMAT_LONG;
81+
82+
static void short_print(struct wt_status *s, int null_termination);
83+
7584
static int opt_parse_m(const struct option *opt, const char *arg, int unset)
7685
{
7786
struct strbuf *buf = opt->value;
@@ -105,6 +114,12 @@ static struct option builtin_commit_options[] = {
105114
OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
106115
OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
107116
OPT_BOOLEAN(0, "dry-run", &dry_run, "show what would be committed"),
117+
OPT_SET_INT(0, "short", &status_format, "show status concisely",
118+
STATUS_FORMAT_SHORT),
119+
OPT_SET_INT(0, "porcelain", &status_format,
120+
"show porcelain output format", STATUS_FORMAT_PORCELAIN),
121+
OPT_BOOLEAN('z', "null", &null_termination,
122+
"terminate entries with NUL"),
108123
OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
109124
{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
110125
OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
@@ -363,7 +378,18 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
363378
s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
364379

365380
wt_status_collect(s);
366-
wt_status_print(s);
381+
382+
switch (status_format) {
383+
case STATUS_FORMAT_SHORT:
384+
short_print(s, null_termination);
385+
break;
386+
case STATUS_FORMAT_PORCELAIN:
387+
short_print(s, null_termination);
388+
break;
389+
case STATUS_FORMAT_LONG:
390+
wt_status_print(s);
391+
break;
392+
}
367393

368394
return s->commitable;
369395
}
@@ -821,6 +847,11 @@ static int parse_and_validate_options(int argc, const char *argv[],
821847
else if (interactive && argc > 0)
822848
die("Paths with --interactive does not make sense.");
823849

850+
if (null_termination && status_format == STATUS_FORMAT_LONG)
851+
status_format = STATUS_FORMAT_PORCELAIN;
852+
if (status_format != STATUS_FORMAT_LONG)
853+
dry_run = 1;
854+
824855
return argc;
825856
}
826857

@@ -991,12 +1022,6 @@ static void short_print(struct wt_status *s, int null_termination)
9911022
int cmd_status(int argc, const char **argv, const char *prefix)
9921023
{
9931024
struct wt_status s;
994-
static int null_termination;
995-
static enum {
996-
STATUS_FORMAT_LONG,
997-
STATUS_FORMAT_SHORT,
998-
STATUS_FORMAT_PORCELAIN,
999-
} status_format = STATUS_FORMAT_LONG;
10001025
unsigned char sha1[20];
10011026
static struct option builtin_status_options[] = {
10021027
OPT__VERBOSE(&verbose),

0 commit comments

Comments
 (0)