Commands such as `commit` and `tag` that let you edit
messages consider a line that begins with this character
commented, and removes them after the editor returns
- (default '#').
+ (default '#'). Note that this option can take values larger than
+ a byte (whether a single multi-byte character, or you
+ could even go wild with a multi-character sequence).
+
If set to "auto", `git-commit` would select a character that is not
the beginning character of any line in existing commit messages.
return config_error_nonbool(var);
else if (!strcasecmp(value, "auto"))
auto_comment_line_char = 1;
- else if (value[0] && !value[1]) {
- if (value[0] == '\n')
- return error(_("core.commentChar cannot be newline"));
- comment_line_str = xstrfmt("%c", value[0]);
+ else if (value[0]) {
+ if (strchr(value, '\n'))
+ return error(_("core.commentChar cannot contain newline"));
+ comment_line_str = xstrdup(value);
auto_comment_line_char = 0;
} else
- return error(_("core.commentChar should only be one ASCII character"));
+ return error(_("core.commentChar must have at least one character"));
return 0;
}
test_expect_success 'newline as commentchar is forbidden' '
test_must_fail git -c core.commentChar="$LF" stripspace -s 2>err &&
- grep "core.commentChar cannot be newline" err
+ grep "core.commentChar cannot contain newline" err
+'
+
+test_expect_success 'empty commentchar is forbidden' '
+ test_must_fail git -c core.commentchar= stripspace -s 2>err &&
+ grep "core.commentChar must have at least one character" err
'
test_expect_success '-c with single line' '
test_grep "Aborting commit due to empty commit message." err
'
+test_expect_success 'verbose diff is stripped with multi-byte comment char' '
+ (
+ GIT_EDITOR=cat &&
+ export GIT_EDITOR &&
+ test_must_fail git -c core.commentchar="foo>" commit -a -v >out 2>err
+ ) &&
+ grep "^foo> " out &&
+ test_grep "Aborting commit due to empty commit message." err
+'
+
test_expect_success 'status does not verbose without --verbose' '
git status >actual &&
! grep "^diff --git" actual
test_expect_success "status (core.commentchar with two chars with submodule summary)" '
test_config core.commentchar ";;" &&
- test_must_fail git -c status.displayCommentPrefix=true status
+ sed "s/^/;/" <expect >expect.double &&
+ git -c status.displayCommentPrefix=true status >output &&
+ test_cmp expect.double output
'
test_expect_success "--ignore-submodules=all suppresses submodule summary" '