From: Marcus Griep <marcus@griep.us>
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>, Marcus Griep <marcus@griep.us>
Subject: [PATCH] git-commit: '--no-status' Allow suppression of status summary in commit msg
Date: Thu, 28 Aug 2008 14:46:55 -0400 [thread overview]
Message-ID: <1219949215-10189-1-git-send-email-marcus@griep.us> (raw)
Currently, using any editor to edit a commit message for 'git commit'
kicks of a 'git status' which is then included as comments to give
the commit author some context. However, in some situations, such as
having a working tree of many hundred thousand files or on an inefficient
filesystem, a 'git status' can take a long time to process before
displaying the commit for editing.
This patch provides an option to disable the status summary, documents it
and provides test cases for its operation.
Signed-off-by: Marcus Griep <marcus@griep.us>
---
Documentation/git-commit.txt | 9 +++++++++
builtin-commit.c | 16 +++++++++++-----
t/t7500-commit.sh | 32 ++++++++++++++++++++++++++++++++
t/t7500/check-for-status | 9 +++++++++
4 files changed, 61 insertions(+), 5 deletions(-)
create mode 100755 t/t7500/check-for-status
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 0e25bb8..0d5d35c 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -190,6 +190,15 @@ specified.
--quiet::
Suppress commit summary message.
+-S::
+--no-status::
+ Suppress inclusion of the git status summary comments
+ that are normally included when the commit message
+ editor is invoked. This can be helpful if `git status`
+ is an expensive operation on your machine, and you
+ don't wish to incur that cost when editing a commit
+ message.
+
\--::
Do not interpret any more arguments as options.
diff --git a/builtin-commit.c b/builtin-commit.c
index 649c8be..153f436 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -51,7 +51,7 @@ static const char *template_file;
static char *edit_message, *use_message;
static char *author_name, *author_email, *author_date;
static int all, edit_flag, also, interactive, only, amend, signoff;
-static int quiet, verbose, no_verify, allow_empty;
+static int quiet, verbose, no_verify, no_status, allow_empty;
static char *untracked_files_arg;
/*
* The default commit message cleanup mode will remove the lines
@@ -103,6 +103,7 @@ static struct option builtin_commit_options[] = {
OPT_BOOLEAN(0, "interactive", &interactive, "interactively add files"),
OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
+ OPT_BOOLEAN('S', "no-status", &no_status, "don't include status summary comments in editor"),
OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
{ 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" },
OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
@@ -590,10 +591,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
if (ident_shown)
fprintf(fp, "#\n");
- saved_color_setting = wt_status_use_color;
- wt_status_use_color = 0;
- commitable = run_status(fp, index_file, prefix, 1);
- wt_status_use_color = saved_color_setting;
+ if (!no_status) {
+ saved_color_setting = wt_status_use_color;
+ wt_status_use_color = 0;
+ commitable = run_status(fp, index_file, prefix, 1);
+ wt_status_use_color = saved_color_setting;
+ }
} else {
struct rev_info rev;
unsigned char sha1[20];
@@ -893,6 +896,9 @@ static int git_commit_config(const char *k, const char *v, void *cb)
if (!strcmp(k, "commit.template"))
return git_config_string(&template_file, k, v);
+ if (!strcmp(k, "commit.nostatus"))
+ return git_config_bool_or_int(k, v, &no_status);
+
return git_status_config(k, v, cb);
}
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index 7ae0bd0..5579463 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -186,4 +186,36 @@ test_expect_success 'commit message from stdin' '
commit_msg_is "Log with foo word"
'
+test_expect_success 'commit message in editor should include status' '
+ echo "Test status" > fooey &&
+ git add fooey &&
+ (
+ test_set_editor "$TEST_DIRECTORY"/t7500/check-for-status &&
+ git commit
+ ) &&
+ commit_msg_is "Status"
+'
+
+test_expect_success 'no-status flag should suppress including status summary' '
+ echo "Test no-status" > fooey &&
+ git add fooey &&
+ (
+ test_set_editor "$TEST_DIRECTORY"/t7500/check-for-status &&
+ git commit --no-status
+ ) &&
+ commit_msg_is "No Status"
+'
+
+test_expect_success 'no-status config should suppress status summary' '
+ echo "Test no-status config" > fooey &&
+ git add fooey &&
+ (
+ git config commit.nostatus true &&
+ test_set_editor "$TEST_DIRECTORY"/t7500/check-for-status &&
+ git commit &&
+ git config --unset commit.nostatus
+ ) &&
+ commit_msg_is "No Status"
+'
+
test_done
diff --git a/t/t7500/check-for-status b/t/t7500/check-for-status
new file mode 100755
index 0000000..5c6efdf
--- /dev/null
+++ b/t/t7500/check-for-status
@@ -0,0 +1,9 @@
+#!/bin/sh
+val=`sed -n 's/^# On branch .*$/1/p' "$1"`
+cat "$1"
+if [ $val ]; then
+ echo Status >> "$1"
+else
+ echo No Status >> "$1"
+fi
+exit 0
--
1.6.0.rc3.286.gd4df
next reply other threads:[~2008-08-28 18:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-28 18:46 Marcus Griep [this message]
2008-08-28 19:09 ` [PATCH] git-commit: '--no-status' Allow suppression of status summary in commit msg Junio C Hamano
2008-08-28 19:34 ` Alex Riesen
2008-08-28 19:13 ` Alex Riesen
2008-08-28 19:24 ` Marcus Griep
2008-08-29 5:39 ` Marius Storm-Olsen
2008-08-29 5:49 ` Marius Storm-Olsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1219949215-10189-1-git-send-email-marcus@griep.us \
--to=marcus@griep.us \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).