Skip to content

Commit 801a88c

Browse files
committed
commit: deprecate support for core.commentString=auto
When 'core.commentString' is set to "auto" then 'git commit' will automatically select the comment character ensuring that it does not match the start of any of the lines in the commit message. This was introduced by commit 84c9dc2 (commit: allow core.commentChar=auto for character auto selection, 2014-05-17) The motivation seems to be to avoid commenting out lines from the existing message when amending a commit that was created with a message from a file. Unfortunately this feature does not work with: - commit message templates that contain comments including the conflict comments added by "git commands" etc. - prepare-commit-msg hooks that introduce comments. - the 'fixup' and 'squash' commands of "git rebase -i". - when creating a commit with "git commit --cleanup=strip -F <file>" It is also ignored by "git notes" when amending a note. The issues with comments comming from a template or a hook and the failure to strip comments from a file are a consequence of the design of this feature and are therefore hard to fix. The other issues could in principle be fixed but it would complicate the implementation. As the costs of this feature seem to outweigh the befits deprecate it and remove it in Git 3.0. If someone comes up with some patches that fix all the issues in a maintainable way then I'd be happy to see this change reverted. Signed-off-by: Phillip Wood <[email protected]>
1 parent f0135a9 commit 801a88c

File tree

8 files changed

+41
-6
lines changed

8 files changed

+41
-6
lines changed

Documentation/BreakingChanges.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ These features will be removed.
183183
timeframe, in preference to its synonym "--annotate-stdin". Git 3.0
184184
removes the support for "--stdin" altogether.
185185

186+
* Support for `core.commentString=auto` has been deprecated and will
187+
be removed in Git 3.0.
188+
+
189+
186190

187191
== Superseded features that will not be deprecated
188192

Documentation/config/advice.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ all advice messages.
3838
configuration variable for how to set a given remote
3939
to be used by default in some situations where this
4040
advice would be printed.
41+
commitAutoCommentChar::
42+
Shown when `core.commentString` is set to the deprecated
43+
value `auto`.
4144
commitBeforeMerge::
4245
Shown when linkgit:git-merge[1] refuses to
4346
merge to avoid overwriting local changes.

Documentation/config/core.adoc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,25 @@ core.commentString::
531531
commented, and removes them after the editor returns
532532
(default '#').
533533
+
534-
If set to "auto", `git-commit` would select a character that is not
534+
ifndef::with-breaking-changes[]
535+
If set to "auto", `git-commit` will select a character that is not
535536
the beginning character of any line in existing commit messages.
536-
+
537+
Support for this value is deprecated and will be removed in Git 3.0
538+
due to the following limitations:
539+
+
540+
--
541+
* It is incompatible with adding comments in a commit message
542+
template. This includes the conflicts comments added to
543+
the commit message by `cherry-pick`, `merge`, `rebase` and
544+
`revert`.
545+
* It is incompatible with adding comments to the commit message
546+
in the `prepare-commit-msg` hook.
547+
* It is incompatible with the `fixup` and `squash` commands when
548+
rebasing,
549+
* It is not respected by `git notes`
550+
--
551+
+
552+
endif::with-breaking-changes[]
537553
Note that these two variables are aliases of each other, and in modern
538554
versions of Git you are free to use a string (e.g., `//` or `⁑⁕⁑`) with
539555
`commentChar`. Versions of Git prior to v2.45.0 will ignore

advice.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static struct {
5050
[ADVICE_AMBIGUOUS_FETCH_REFSPEC] = { "ambiguousFetchRefspec" },
5151
[ADVICE_AM_WORK_DIR] = { "amWorkDir" },
5252
[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] = { "checkoutAmbiguousRemoteBranchName" },
53+
[ADVICE_COMMIT_AUTO_COMMENT_CHAR] = { "commitAutoCommentChar" },
5354
[ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge" },
5455
[ADVICE_DEFAULT_BRANCH_NAME] = { "defaultBranchName" },
5556
[ADVICE_DETACHED_HEAD] = { "detachedHead" },

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum advice_type {
1717
ADVICE_AMBIGUOUS_FETCH_REFSPEC,
1818
ADVICE_AM_WORK_DIR,
1919
ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,
20+
ADVICE_COMMIT_AUTO_COMMENT_CHAR,
2021
ADVICE_COMMIT_BEFORE_MERGE,
2122
ADVICE_DEFAULT_BRANCH_NAME,
2223
ADVICE_DETACHED_HEAD,

builtin/commit.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,12 +683,17 @@ static int author_date_is_interesting(void)
683683
return author_message || force_date;
684684
}
685685

686+
#ifndef WITH_BREAKING_CHANGES
686687
static void adjust_comment_line_char(const struct strbuf *sb)
687688
{
688689
char candidates[] = "#;@!$%^&|:";
689690
char *candidate;
690691
const char *p;
691692

693+
advise_if_enabled(ADVICE_COMMIT_AUTO_COMMENT_CHAR,
694+
_("Setting 'core.commentString=auto' is deprecated and "
695+
"will be removed in git 3.0"));
696+
692697
if (!memchr(sb->buf, candidates[0], sb->len)) {
693698
free(comment_line_str_to_free);
694699
comment_line_str = comment_line_str_to_free =
@@ -716,6 +721,7 @@ static void adjust_comment_line_char(const struct strbuf *sb)
716721
free(comment_line_str_to_free);
717722
comment_line_str = comment_line_str_to_free = xstrfmt("%c", *p);
718723
}
724+
#endif /* WITH_BREAKING_CHANGES */
719725

720726
static void prepare_amend_commit(struct commit *commit, struct strbuf *sb,
721727
struct pretty_print_context *ctx)
@@ -912,8 +918,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
912918
if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
913919
die_errno(_("could not write commit template"));
914920

921+
#ifndef WITH_BREAKING_CHANGES
915922
if (auto_comment_line_char)
916923
adjust_comment_line_char(&sb);
924+
#endif /* WITH_BREAKING_CHANGES */
917925
strbuf_release(&sb);
918926

919927
/* This checks if committer ident is explicitly given */

t/t3404-rebase-interactive.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ test_expect_success 'rebase -i respects core.commentchar' '
11761176
test B = $(git cat-file commit HEAD^ | sed -ne \$p)
11771177
'
11781178

1179-
test_expect_success 'rebase -i respects core.commentchar=auto' '
1179+
test_expect_success !WITH_BREAKING_CHANGES 'rebase -i respects core.commentchar=auto' '
11801180
test_config core.commentchar auto &&
11811181
write_script copy-edit-script.sh <<-\EOF &&
11821182
cp "$1" edit-script

t/t7502-commit-porcelain.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -956,13 +956,15 @@ test_expect_success 'commit --status with custom comment character' '
956956
test_grep "^; Changes to be committed:" .git/COMMIT_EDITMSG
957957
'
958958

959-
test_expect_success 'switch core.commentchar' '
959+
test_expect_success !WITH_BREAKING_CHANGES 'switch core.commentchar' '
960960
test_commit "#foo" foo &&
961-
GIT_EDITOR=.git/FAKE_EDITOR git -c core.commentChar=auto commit --amend &&
961+
GIT_EDITOR=.git/FAKE_EDITOR git -c core.commentChar=auto commit --amend 2>actual &&
962+
test_grep "${SQ}core.commentString=auto${SQ} is deprecated" actual &&
963+
test_grep advice.commitAutoCommentChar actual &&
962964
test_grep "^; Changes to be committed:" .git/COMMIT_EDITMSG
963965
'
964966

965-
test_expect_success 'switch core.commentchar but out of options' '
967+
test_expect_success !WITH_BREAKING_CHANGES 'switch core.commentchar but out of options' '
966968
cat >text <<\EOF &&
967969
# 1
968970
; 2

0 commit comments

Comments
 (0)