From 4fb5166ab5e1b83ee6211ac77d76173f881ebfdb Mon Sep 17 00:00:00 2001 From: Jorge Juan Garcia Garcia Date: Tue, 11 Jun 2013 15:34:04 +0200 Subject: status: introduce status.short to enable --short by default Some people always run 'git status -s'. The configuration variable status.short allows to set it by default. Signed-off-by: Jorge Juan Garcia Garcia Signed-off-by: Mathieu Lienard--Mayor Reviewed-by: Matthieu Moy Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano diff --git a/Documentation/config.txt b/Documentation/config.txt index 6e53fc5..1983bf7 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -2066,6 +2066,10 @@ status.relativePaths:: relative to the repository root (this was the default for Git prior to v1.5.4). +status.short:: + Set to true to enable --short by default in linkgit:git-status[1]. + The option --no-short takes precedence over this variable. + status.showUntrackedFiles:: By default, linkgit:git-status[1] and linkgit:git-commit[1] show files which are not currently tracked by Git. Directories which diff --git a/builtin/commit.c b/builtin/commit.c index d2f30d9..b2f41de 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1110,6 +1110,13 @@ static int git_status_config(const char *k, const char *v, void *cb) s->submodule_summary = -1; return 0; } + if (!strcmp(k, "status.short")) { + if (git_config_bool(k, v)) + status_format = STATUS_FORMAT_SHORT; + else + status_format = STATUS_FORMAT_NONE; + return 0; + } if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) { s->use_color = git_config_colorbool(k, v); return 0; diff --git a/t/t7508-status.sh b/t/t7508-status.sh index e2ffdac..33cadd0 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -1335,4 +1335,34 @@ test_expect_failure '.git/config ignore=all suppresses submodule summary' ' git config -f .gitmodules --remove-section submodule.subname ' +test_expect_success 'setup of test environment' ' + git config status.showUntrackedFiles no && + git status -s >expected_short && + git status --no-short >expected_noshort +' + +test_expect_success '"status.short=true" same as "-s"' ' + git -c status.short=true status >actual && + test_cmp expected_short actual +' + +test_expect_success '"status.short=true" weaker than "--no-short"' ' + git -c status.short=true status --no-short >actual && + test_cmp expected_noshort actual +' + +test_expect_success '"status.short=false" same as "--no-short"' ' + git -c status.short=false status >actual && + test_cmp expected_noshort actual +' + +test_expect_success '"status.short=false" weaker than "-s"' ' + git -c status.short=false status -s >actual && + test_cmp expected_short actual +' + +test_expect_success 'Restore default test environment' ' + git config --unset status.showUntrackedFiles +' + test_done -- cgit v0.10.2-6-g49f6 From ec85d0700faac679ec27eeacad2bcaa6d9bc8322 Mon Sep 17 00:00:00 2001 From: Jorge Juan Garcia Garcia Date: Tue, 11 Jun 2013 15:34:05 +0200 Subject: status: introduce status.branch to enable --branch by default Some people often run 'git status -b'. The config variable status.branch allows to set it by default. Signed-off-by: Jorge Juan Garcia Garcia Signed-off-by: Mathieu Lienard--Mayor Reviewed-by: Matthieu Moy Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano diff --git a/Documentation/config.txt b/Documentation/config.txt index 1983bf7..ecdcd6d 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -2070,6 +2070,10 @@ status.short:: Set to true to enable --short by default in linkgit:git-status[1]. The option --no-short takes precedence over this variable. +status.branch:: + Set to true to enable --branch by default in linkgit:git-status[1]. + The option --no-branch takes precedence over this variable. + status.showUntrackedFiles:: By default, linkgit:git-status[1] and linkgit:git-commit[1] show files which are not currently tracked by Git. Directories which diff --git a/builtin/commit.c b/builtin/commit.c index b2f41de..d6c8e20 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1117,6 +1117,10 @@ static int git_status_config(const char *k, const char *v, void *cb) status_format = STATUS_FORMAT_NONE; return 0; } + if (!strcmp(k, "status.branch")) { + s->show_branch = git_config_bool(k, v); + return 0; + } if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) { s->use_color = git_config_colorbool(k, v); return 0; diff --git a/t/t7508-status.sh b/t/t7508-status.sh index 33cadd0..498332c 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -1361,6 +1361,33 @@ test_expect_success '"status.short=false" weaker than "-s"' ' test_cmp expected_short actual ' +test_expect_success '"status.branch=true" same as "-b"' ' + git status -sb >expected_branch && + git -c status.branch=true status -s >actual && + test_cmp expected_branch actual +' + +test_expect_success '"status.branch=true" different from "--no-branch"' ' + git status -s --no-branch >expected_nobranch && + git -c status.branch=true status -s >actual && + test_must_fail test_cmp expected_nobranch actual +' + +test_expect_success '"status.branch=true" weaker than "--no-branch"' ' + git -c status.branch=true status -s --no-branch >actual && + test_cmp expected_nobranch actual +' + +test_expect_success '"status.branch=false" same as "--no-branch"' ' + git -c status.branch=false status -s >actual && + test_cmp expected_nobranch actual +' + +test_expect_success '"status.branch=false" weaker than "-b"' ' + git -c status.branch=false status -sb >actual && + test_cmp expected_branch actual +' + test_expect_success 'Restore default test environment' ' git config --unset status.showUntrackedFiles ' -- cgit v0.10.2-6-g49f6 From f0915cbaf476d63f72c284057680809ed24fbe0d Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Mon, 24 Jun 2013 18:15:12 +0530 Subject: commit: make it work with status.short With "status.short" set, it is now impossible to commit with status.short set, because it acts like "git commit --short", and it is impossible to differentiate between a status_format set by the command-line option parser versus that set by the config parser. To alleviate this problem, clear status_format as soon as the config parser has finished its work. Signed-off-by: Ramkumar Ramachandra Signed-off-by: Junio C Hamano diff --git a/builtin/commit.c b/builtin/commit.c index d6c8e20..0da944f 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1441,6 +1441,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) wt_status_prepare(&s); gitmodules_config(); git_config(git_commit_config, &s); + status_format = STATUS_FORMAT_NONE; /* Ignore status.short */ determine_whence(&s); s.colopts = 0; -- cgit v0.10.2-6-g49f6 From 84b4202d804c7faec76f3eab22744b6288c63481 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 24 Jun 2013 11:41:40 -0700 Subject: status/commit: make sure --porcelain is not affected by user-facing config The recent addition of status.branch started affecting what is shown when "git status --porcelain" is run by mistake. Identify the configuration items that should be ignored under "--porcelain" option, introduce a "deferred config" mechanism to keep the values read from the configuration, and decide what value to use only after we read both from configuration and command line. Signed-off-by: Junio C Hamano diff --git a/builtin/commit.c b/builtin/commit.c index 0da944f..6f8cb04 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -111,12 +111,14 @@ static int show_ignored_in_status; static const char *only_include_assumed; static struct strbuf message = STRBUF_INIT; -static enum { +static enum status_format { STATUS_FORMAT_NONE = 0, STATUS_FORMAT_LONG, STATUS_FORMAT_SHORT, - STATUS_FORMAT_PORCELAIN -} status_format; + STATUS_FORMAT_PORCELAIN, + + STATUS_FORMAT_UNSPECIFIED +} status_format = STATUS_FORMAT_UNSPECIFIED; static int opt_parse_m(const struct option *opt, const char *arg, int unset) { @@ -457,6 +459,9 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int case STATUS_FORMAT_PORCELAIN: wt_porcelain_print(s); break; + case STATUS_FORMAT_UNSPECIFIED: + die("BUG: finalize_deferred_config() should have been called"); + break; case STATUS_FORMAT_NONE: case STATUS_FORMAT_LONG: wt_status_print(s); @@ -958,6 +963,42 @@ static const char *read_commit_message(const char *name) return logmsg_reencode(commit, NULL, out_enc); } +/* + * Enumerate what needs to be propagated when --porcelain + * is not in effect here. + */ +static struct status_deferred_config { + enum status_format status_format; + int show_branch; +} status_deferred_config = { + STATUS_FORMAT_UNSPECIFIED, + -1 /* unspecified */ +}; + +static void finalize_deferred_config(struct wt_status *s) +{ + int use_deferred_config = (status_format != STATUS_FORMAT_PORCELAIN && + !s->null_termination); + + if (s->null_termination) { + if (status_format == STATUS_FORMAT_NONE || + status_format == STATUS_FORMAT_UNSPECIFIED) + status_format = STATUS_FORMAT_PORCELAIN; + else if (status_format == STATUS_FORMAT_LONG) + die(_("--long and -z are incompatible")); + } + + if (use_deferred_config && status_format == STATUS_FORMAT_UNSPECIFIED) + status_format = status_deferred_config.status_format; + if (status_format == STATUS_FORMAT_UNSPECIFIED) + status_format = STATUS_FORMAT_NONE; + + if (use_deferred_config && s->show_branch < 0) + s->show_branch = status_deferred_config.show_branch; + if (s->show_branch < 0) + s->show_branch = 0; +} + static int parse_and_validate_options(int argc, const char *argv[], const struct option *options, const char * const usage[], @@ -968,6 +1009,7 @@ static int parse_and_validate_options(int argc, const char *argv[], int f = 0; argc = parse_options(argc, argv, prefix, options, usage, 0); + finalize_deferred_config(s); if (force_author && !strchr(force_author, '>')) force_author = find_author_by_nickname(force_author); @@ -1052,12 +1094,6 @@ static int parse_and_validate_options(int argc, const char *argv[], if (all && argc > 0) die(_("Paths with -a does not make sense.")); - if (s->null_termination) { - if (status_format == STATUS_FORMAT_NONE) - status_format = STATUS_FORMAT_PORCELAIN; - else if (status_format == STATUS_FORMAT_LONG) - die(_("--long and -z are incompatible")); - } if (status_format != STATUS_FORMAT_NONE) dry_run = 1; @@ -1112,13 +1148,13 @@ static int git_status_config(const char *k, const char *v, void *cb) } if (!strcmp(k, "status.short")) { if (git_config_bool(k, v)) - status_format = STATUS_FORMAT_SHORT; + status_deferred_config.status_format = STATUS_FORMAT_SHORT; else - status_format = STATUS_FORMAT_NONE; + status_deferred_config.status_format = STATUS_FORMAT_NONE; return 0; } if (!strcmp(k, "status.branch")) { - s->show_branch = git_config_bool(k, v); + status_deferred_config.show_branch = git_config_bool(k, v); return 0; } if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) { @@ -1163,8 +1199,8 @@ int cmd_status(int argc, const char **argv, const char *prefix) OPT__VERBOSE(&verbose, N_("be verbose")), OPT_SET_INT('s', "short", &status_format, N_("show status concisely"), STATUS_FORMAT_SHORT), - OPT_BOOLEAN('b', "branch", &s.show_branch, - N_("show branch information")), + OPT_BOOL('b', "branch", &s.show_branch, + N_("show branch information")), OPT_SET_INT(0, "porcelain", &status_format, N_("machine-readable output"), STATUS_FORMAT_PORCELAIN), @@ -1197,13 +1233,7 @@ int cmd_status(int argc, const char **argv, const char *prefix) builtin_status_options, builtin_status_usage, 0); finalize_colopts(&s.colopts, -1); - - if (s.null_termination) { - if (status_format == STATUS_FORMAT_NONE) - status_format = STATUS_FORMAT_PORCELAIN; - else if (status_format == STATUS_FORMAT_LONG) - die(_("--long and -z are incompatible")); - } + finalize_deferred_config(&s); handle_untracked_files_arg(&s); if (show_ignored_in_status) @@ -1232,6 +1262,9 @@ int cmd_status(int argc, const char **argv, const char *prefix) case STATUS_FORMAT_PORCELAIN: wt_porcelain_print(&s); break; + case STATUS_FORMAT_UNSPECIFIED: + die("BUG: finalize_deferred_config() should have been called"); + break; case STATUS_FORMAT_NONE: case STATUS_FORMAT_LONG: s.verbose = verbose; @@ -1400,7 +1433,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) OPT_BOOLEAN(0, "dry-run", &dry_run, N_("show what would be committed")), OPT_SET_INT(0, "short", &status_format, N_("show status concisely"), STATUS_FORMAT_SHORT), - OPT_BOOLEAN(0, "branch", &s.show_branch, N_("show branch information")), + OPT_BOOL(0, "branch", &s.show_branch, N_("show branch information")), OPT_SET_INT(0, "porcelain", &status_format, N_("machine-readable output"), STATUS_FORMAT_PORCELAIN), OPT_SET_INT(0, "long", &status_format, diff --git a/t/t7508-status.sh b/t/t7508-status.sh index 498332c..ac3d0fe 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -1378,6 +1378,11 @@ test_expect_success '"status.branch=true" weaker than "--no-branch"' ' test_cmp expected_nobranch actual ' +test_expect_success '"status.branch=true" weaker than "--porcelain"' ' + git -c status.branch=true status --porcelain >actual && + test_cmp expected_nobranch actual +' + test_expect_success '"status.branch=false" same as "--no-branch"' ' git -c status.branch=false status -s >actual && test_cmp expected_nobranch actual diff --git a/wt-status.c b/wt-status.c index bf84a86..6778755 100644 --- a/wt-status.c +++ b/wt-status.c @@ -127,6 +127,7 @@ void wt_status_prepare(struct wt_status *s) s->change.strdup_strings = 1; s->untracked.strdup_strings = 1; s->ignored.strdup_strings = 1; + s->show_branch = -1; /* unspecified */ } static void wt_status_print_unmerged_header(struct wt_status *s) -- cgit v0.10.2-6-g49f6