]> Pileus Git - ~andy/git/commitdiff
commit: make default of "cleanup" option configurable
authorRalf Thielow <ralf.thielow@gmail.com>
Thu, 10 Jan 2013 17:45:59 +0000 (18:45 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 Jan 2013 19:45:02 +0000 (11:45 -0800)
The default of the "cleanup" option in "git commit"
is not configurable. Users who don't want to use the
default have to pass this option on every commit since
there's no way to configure it. This commit introduces
a new config option "commit.cleanup" which can be used
to change the default of the "cleanup" option in
"git commit".

Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
Documentation/git-commit.txt
builtin/commit.c
t/t7500/add-content-and-comment [new file with mode: 0755]
t/t7502-commit.sh

index d5809e0e8c4dca414a863cfd019a6f8860c46c4d..8f0ce9eae42ebdf56d239a18412deffb27020aa0 100644 (file)
@@ -923,6 +923,15 @@ column.tag::
        Specify whether to output tag listing in `git tag` in columns.
        See `column.ui` for details.
 
+commit.cleanup::
+       This setting overrides the default of the `--cleanup` option in
+       `git commit`. See linkgit:git-commit[1] for details. Changing the
+       default can be useful when you always want to keep lines that begin
+       with comment character `#` in your log message, in which case you
+       would do `git config commit.cleanup whitespace` (note that you will
+       have to remove the help lines that begin with `#` in the commit log
+       template yourself, if you do this).
+
 commit.status::
        A boolean to enable/disable inclusion of status information in the
        commit message template when using an editor to prepare the commit
index 7bdb039d5ee9c6ed6c19c70173c733860de2d5b7..41b27da325053a9a817160364ac50e5140f5891c 100644 (file)
@@ -179,7 +179,9 @@ OPTIONS
        only if the message is to be edited. Otherwise only whitespace
        removed. The 'verbatim' mode does not change message at all,
        'whitespace' removes just leading/trailing whitespace lines
-       and 'strip' removes both whitespace and commentary.
+       and 'strip' removes both whitespace and commentary. The default
+       can be changed by the 'commit.cleanup' configuration variable
+       (see linkgit:git-config[1]).
 
 -e::
 --edit::
index d6dd3df8b1e1f449e7781bdb033f5cfa11753436..7c2a3d48b4ac6bf6f55539946adacb433b51dabb 100644 (file)
@@ -103,7 +103,7 @@ static enum {
        CLEANUP_NONE,
        CLEANUP_ALL
 } cleanup_mode;
-static char *cleanup_arg;
+static const char *cleanup_arg;
 
 static enum commit_whence whence;
 static int use_editor = 1, include_status = 1;
@@ -1320,6 +1320,8 @@ static int git_commit_config(const char *k, const char *v, void *cb)
                include_status = git_config_bool(k, v);
                return 0;
        }
+       if (!strcmp(k, "commit.cleanup"))
+               return git_config_string(&cleanup_arg, k, v);
 
        status = git_gpg_config(k, v, NULL);
        if (status)
diff --git a/t/t7500/add-content-and-comment b/t/t7500/add-content-and-comment
new file mode 100755 (executable)
index 0000000..c4dccff
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+echo "commit message" >> "$1"
+echo "# comment" >> "$1"
+exit 0
+
index 1a5cb6983c527b6d3e1ad6fad427d3513e8704b1..b1c76483866f55b4429fc76e7035e65984e7b4c2 100755 (executable)
@@ -4,6 +4,15 @@ test_description='git commit porcelain-ish'
 
 . ./test-lib.sh
 
+commit_msg_is () {
+       expect=commit_msg_is.expect
+       actual=commit_msg_is.actual
+
+       printf "%s" "$(git log --pretty=format:%s%b -1)" >$actual &&
+       printf "%s" "$1" >$expect &&
+       test_i18ncmp $expect $actual
+}
+
 # Arguments: [<prefix] [<commit message>] [<commit options>]
 check_summary_oneline() {
        test_tick &&
@@ -168,7 +177,7 @@ test_expect_success 'verbose respects diff config' '
        git config --unset color.diff
 '
 
-test_expect_success 'cleanup commit messages (verbatim,-t)' '
+test_expect_success 'cleanup commit messages (verbatim option,-t)' '
 
        echo >>negative &&
        { echo;echo "# text";echo; } >expect &&
@@ -178,7 +187,7 @@ test_expect_success 'cleanup commit messages (verbatim,-t)' '
 
 '
 
-test_expect_success 'cleanup commit messages (verbatim,-F)' '
+test_expect_success 'cleanup commit messages (verbatim option,-F)' '
 
        echo >>negative &&
        git commit --cleanup=verbatim -F expect -a &&
@@ -187,7 +196,7 @@ test_expect_success 'cleanup commit messages (verbatim,-F)' '
 
 '
 
-test_expect_success 'cleanup commit messages (verbatim,-m)' '
+test_expect_success 'cleanup commit messages (verbatim option,-m)' '
 
        echo >>negative &&
        git commit --cleanup=verbatim -m "$(cat expect)" -a &&
@@ -196,7 +205,7 @@ test_expect_success 'cleanup commit messages (verbatim,-m)' '
 
 '
 
-test_expect_success 'cleanup commit messages (whitespace,-F)' '
+test_expect_success 'cleanup commit messages (whitespace option,-F)' '
 
        echo >>negative &&
        { echo;echo "# text";echo; } >text &&
@@ -207,7 +216,7 @@ test_expect_success 'cleanup commit messages (whitespace,-F)' '
 
 '
 
-test_expect_success 'cleanup commit messages (strip,-F)' '
+test_expect_success 'cleanup commit messages (strip option,-F)' '
 
        echo >>negative &&
        { echo;echo "# text";echo sample;echo; } >text &&
@@ -218,7 +227,7 @@ test_expect_success 'cleanup commit messages (strip,-F)' '
 
 '
 
-test_expect_success 'cleanup commit messages (strip,-F,-e)' '
+test_expect_success 'cleanup commit messages (strip option,-F,-e)' '
 
        echo >>negative &&
        { echo;echo sample;echo; } >text &&
@@ -231,10 +240,71 @@ echo "sample
 # Please enter the commit message for your changes. Lines starting
 # with '#' will be ignored, and an empty message aborts the commit." >expect
 
-test_expect_success 'cleanup commit messages (strip,-F,-e): output' '
+test_expect_success 'cleanup commit messages (strip option,-F,-e): output' '
        test_i18ncmp expect actual
 '
 
+test_expect_success 'cleanup commit message (fail on invalid cleanup mode option)' '
+       test_must_fail git commit --cleanup=non-existent
+'
+
+test_expect_success 'cleanup commit message (fail on invalid cleanup mode configuration)' '
+       test_must_fail git -c commit.cleanup=non-existent commit
+'
+
+test_expect_success 'cleanup commit message (no config and no option uses default)' '
+       echo content >>file &&
+       git add file &&
+       test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+       git commit --no-status &&
+       commit_msg_is "commit message"
+'
+
+test_expect_success 'cleanup commit message (option overrides default)' '
+       echo content >>file &&
+       git add file &&
+       test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+       git commit --cleanup=whitespace --no-status &&
+       commit_msg_is "commit message # comment"
+'
+
+test_expect_success 'cleanup commit message (config overrides default)' '
+       echo content >>file &&
+       git add file &&
+       test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+       git -c commit.cleanup=whitespace commit --no-status &&
+       commit_msg_is "commit message # comment"
+'
+
+test_expect_success 'cleanup commit message (option overrides config)' '
+       echo content >>file &&
+       git add file &&
+       test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+       git -c commit.cleanup=whitespace commit --cleanup=default &&
+       commit_msg_is "commit message"
+'
+
+test_expect_success 'cleanup commit message (default, -m)' '
+       echo content >>file &&
+       git add file &&
+       git commit -m "message #comment " &&
+       commit_msg_is "message #comment"
+'
+
+test_expect_success 'cleanup commit message (whitespace option, -m)' '
+       echo content >>file &&
+       git add file &&
+       git commit --cleanup=whitespace --no-status -m "message #comment " &&
+       commit_msg_is "message #comment"
+'
+
+test_expect_success 'cleanup commit message (whitespace config, -m)' '
+       echo content >>file &&
+       git add file &&
+       git -c commit.cleanup=whitespace commit --no-status -m "message #comment " &&
+       commit_msg_is "message #comment"
+'
+
 test_expect_success 'message shows author when it is not equal to committer' '
        echo >>negative &&
        git commit -e -m "sample" -a &&