Skip to content

Commit 8053c27

Browse files
committed
breaking-changes: 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 is not the first character on 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. * prepare-commit-msg hooks that introduce comments. * "git commit --cleanup=strip --edit -F <file>" which means that it is incompatible with - the "fixup" and "squash" commands of "git rebase -i" as the comments added by those commands are then treated as part of the commit message. - the conflict comments added to the commit message by "git cherry-pick", "git rebase" etc. as these comments are then treated as part of the commit message. It is also ignored by "git notes" when amending a note. The issues with comments coming from a template, hook or file are a consequence of the design of this feature and are therefore hard to fix. As the costs of this feature outweigh the benefits 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. The next commit will add some advice for users on how they can update their config settings. Signed-off-by: Phillip Wood <[email protected]> y Conflicts: y Documentation/BreakingChanges.adoc y Conflicts: y config.c
1 parent 56e9aed commit 8053c27

File tree

8 files changed

+40
-7
lines changed

8 files changed

+40
-7
lines changed

Documentation/BreakingChanges.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ These features will be removed.
239239
+
240240
The command will be removed.
241241

242+
* Support for `core.commentString=auto` has been deprecated and will
243+
be removed in Git 3.0.
244+
+
245+
246+
242247
== Superseded features that will not be deprecated
243248

244249
Some features have gained newer replacements that aim to improve the design in

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

builtin/commit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ 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[] = "#;@!$%^&|:";
@@ -720,6 +721,7 @@ static void adjust_comment_line_char(const struct strbuf *sb)
720721
free(comment_line_str_to_free);
721722
comment_line_str = comment_line_str_to_free = xstrfmt("%c", *p);
722723
}
724+
#endif /* WITH_BREAKING_CHANGES */
723725

724726
static void prepare_amend_commit(struct commit *commit, struct strbuf *sb,
725727
struct pretty_print_context *ctx)
@@ -916,8 +918,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
916918
if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
917919
die_errno(_("could not write commit template"));
918920

921+
#ifndef WITH_BREAKING_CHANGES
919922
if (auto_comment_line_char)
920923
adjust_comment_line_char(&sb);
924+
#endif /* WITH_BREAKING_CHANGES */
921925
strbuf_release(&sb);
922926

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

config.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,18 +1535,22 @@ static int git_default_core_config(const char *var, const char *value,
15351535

15361536
if (!strcmp(var, "core.commentchar") ||
15371537
!strcmp(var, "core.commentstring")) {
1538-
if (!value)
1538+
if (!value) {
15391539
return config_error_nonbool(var);
1540-
else if (!strcasecmp(value, "auto")) {
1540+
#ifndef WITH_BREAKING_CHANGES
1541+
} else if (!strcasecmp(value, "auto")) {
15411542
auto_comment_line_char = 1;
15421543
FREE_AND_NULL(comment_line_str_to_free);
15431544
comment_line_str = "#";
1545+
#endif /* WITH_BREAKING_CHANGES */
15441546
} else if (value[0]) {
15451547
if (strchr(value, '\n'))
15461548
return error(_("%s cannot contain newline"), var);
15471549
comment_line_str = value;
15481550
FREE_AND_NULL(comment_line_str_to_free);
1551+
#ifndef WITH_BREAKING_CHANGES
15491552
auto_comment_line_char = 0;
1553+
#endif /* WITH_BREAKING_CHANGES */
15501554
} else
15511555
return error(_("%s must have at least one character"), var);
15521556
return 0;

environment.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ int protect_ntfs = PROTECT_NTFS_DEFAULT;
110110
*/
111111
const char *comment_line_str = "#";
112112
char *comment_line_str_to_free;
113+
#ifndef WITH_BREAKING_CHANGES
113114
int auto_comment_line_char;
115+
#endif /* WITH_BREAKING_CHANGES */
114116

115117
/* This is set by setup_git_directory_gently() and/or git_default_config() */
116118
char *git_work_tree_cfg;

environment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ extern char *excludes_file;
205205
*/
206206
extern const char *comment_line_str;
207207
extern char *comment_line_str_to_free;
208+
#ifndef WITH_BREAKING_CHANGES
208209
extern int auto_comment_line_char;
210+
#endif /* WITH_BREAKING_CHANGES */
209211

210212
# endif /* USE_THE_REPOSITORY_VARIABLE */
211213
#endif /* ENVIRONMENT_H */

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,13 +956,13 @@ 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 &&
961961
GIT_EDITOR=.git/FAKE_EDITOR git -c core.commentChar=auto commit --amend &&
962962
test_grep "^; Changes to be committed:" .git/COMMIT_EDITMSG
963963
'
964964

965-
test_expect_success 'switch core.commentchar but out of options' '
965+
test_expect_success !WITH_BREAKING_CHANGES 'switch core.commentchar but out of options' '
966966
cat >text <<\EOF &&
967967
# 1
968968
; 2

0 commit comments

Comments
 (0)