Allow custom "comment char"
Some users do want to write a line that begin with a pound sign, #, in their commit log message. Many tracking system recognise a token of #<bugid> form, for example. The support we offer these use cases is not very friendly to the end users. They have a choice between - Don't do it. Avoid such a line by rewrapping or indenting; and - Use --cleanup=whitespace but remove all the hint lines we add. Give them a way to set a custom comment char, e.g. $ git -c core.commentchar="%" commit so that they do not have to do either of the two workarounds. [jc: although I started the topic, all the tests and documentation updates, many of the call sites of the new strbuf_add_commented_*() functions, and the change to git-submodule.sh scripted Porcelain are from Ralf.] Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
@ -397,4 +397,39 @@ test_expect_success 'strip comments, too' '
|
||||
test -z "$(echo "# comment" | git stripspace -s)"
|
||||
'
|
||||
|
||||
test_expect_success 'strip comments with changed comment char' '
|
||||
test ! -z "$(echo "; comment" | git -c core.commentchar=";" stripspace)" &&
|
||||
test -z "$(echo "; comment" | git -c core.commentchar=";" stripspace -s)"
|
||||
'
|
||||
|
||||
test_expect_success '-c with single line' '
|
||||
printf "# foo\n" >expect &&
|
||||
printf "foo" | git stripspace -c >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success '-c with single line followed by empty line' '
|
||||
printf "# foo\n#\n" >expect &&
|
||||
printf "foo\n\n" | git stripspace -c >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success '-c with newline only' '
|
||||
printf "#\n" >expect &&
|
||||
printf "\n" | git stripspace -c >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success '--comment-lines with single line' '
|
||||
printf "# foo\n" >expect &&
|
||||
printf "foo" | git stripspace -c >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success '-c with changed comment char' '
|
||||
printf "; foo\n" >expect &&
|
||||
printf "foo" | git -c core.commentchar=";" stripspace -c >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_done
|
||||
|
@ -447,4 +447,11 @@ use_template="-t template"
|
||||
|
||||
try_commit_status_combo
|
||||
|
||||
test_expect_success 'commit --status with custom comment character' '
|
||||
test_when_finished "git config --unset core.commentchar" &&
|
||||
git config core.commentchar ";" &&
|
||||
try_commit --status &&
|
||||
test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG
|
||||
'
|
||||
|
||||
test_done
|
||||
|
@ -1253,6 +1253,56 @@ test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary
|
||||
git config -f .gitmodules --remove-section submodule.subname
|
||||
'
|
||||
|
||||
cat > expect << EOF
|
||||
; On branch master
|
||||
; Changes to be committed:
|
||||
; (use "git reset HEAD <file>..." to unstage)
|
||||
;
|
||||
; modified: sm
|
||||
;
|
||||
; Changes not staged for commit:
|
||||
; (use "git add <file>..." to update what will be committed)
|
||||
; (use "git checkout -- <file>..." to discard changes in working directory)
|
||||
;
|
||||
; modified: dir1/modified
|
||||
; modified: sm (new commits)
|
||||
;
|
||||
; Submodule changes to be committed:
|
||||
;
|
||||
; * sm $head...$new_head (1):
|
||||
; > Add bar
|
||||
;
|
||||
; Submodules changed but not updated:
|
||||
;
|
||||
; * sm $new_head...$head2 (1):
|
||||
; > 2nd commit
|
||||
;
|
||||
; Untracked files:
|
||||
; (use "git add <file>..." to include in what will be committed)
|
||||
;
|
||||
; .gitmodules
|
||||
; dir1/untracked
|
||||
; dir2/modified
|
||||
; dir2/untracked
|
||||
; expect
|
||||
; output
|
||||
; untracked
|
||||
EOF
|
||||
|
||||
test_expect_success "status (core.commentchar with submodule summary)" '
|
||||
test_when_finished "git config --unset core.commentchar" &&
|
||||
git config core.commentchar ";" &&
|
||||
git status >output &&
|
||||
test_i18ncmp expect output
|
||||
'
|
||||
|
||||
test_expect_success "status (core.commentchar with two chars with submodule summary)" '
|
||||
test_when_finished "git config --unset core.commentchar" &&
|
||||
git config core.commentchar ";;" &&
|
||||
git status >output &&
|
||||
test_i18ncmp expect output
|
||||
'
|
||||
|
||||
cat > expect << EOF
|
||||
# On branch master
|
||||
# Changes not staged for commit:
|
||||
|
Reference in New Issue
Block a user