Skip to content

Commit 65791c7

Browse files
phillipwoodgitster
authored andcommitted
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 commits will add a warning and some advice for users on how they can update their config settings. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 084681b commit 65791c7

File tree

8 files changed

+41
-8
lines changed

8 files changed

+41
-8
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 */

environment.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ int protect_ntfs = PROTECT_NTFS_DEFAULT;
122122
*/
123123
const char *comment_line_str = "#";
124124
char *comment_line_str_to_free;
125+
#ifndef WITH_BREAKING_CHANGES
125126
int auto_comment_line_char;
127+
#endif /* !WITH_BREAKING_CHANGES */
126128

127129
/* This is set by setup_git_directory_gently() and/or git_default_config() */
128130
char *git_work_tree_cfg;
@@ -459,18 +461,22 @@ static int git_default_core_config(const char *var, const char *value,
459461

460462
if (!strcmp(var, "core.commentchar") ||
461463
!strcmp(var, "core.commentstring")) {
462-
if (!value)
464+
if (!value) {
463465
return config_error_nonbool(var);
464-
else if (!strcasecmp(value, "auto")) {
466+
#ifndef WITH_BREAKING_CHANGES
467+
} else if (!strcasecmp(value, "auto")) {
465468
auto_comment_line_char = 1;
466469
FREE_AND_NULL(comment_line_str_to_free);
467470
comment_line_str = "#";
471+
#endif /* !WITH_BREAKING_CHANGES */
468472
} else if (value[0]) {
469473
if (strchr(value, '\n'))
470474
return error(_("%s cannot contain newline"), var);
471475
comment_line_str = value;
472476
FREE_AND_NULL(comment_line_str_to_free);
477+
#ifndef WITH_BREAKING_CHANGES
473478
auto_comment_line_char = 0;
479+
#endif /* !WITH_BREAKING_CHANGES */
474480
} else
475481
return error(_("%s must have at least one character"), var);
476482
return 0;

environment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ extern char *excludes_file;
208208
*/
209209
extern const char *comment_line_str;
210210
extern char *comment_line_str_to_free;
211+
#ifndef WITH_BREAKING_CHANGES
211212
extern int auto_comment_line_char;
213+
#endif /* !WITH_BREAKING_CHANGES */
212214

213215
# endif /* USE_THE_REPOSITORY_VARIABLE */
214216
#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/t3418-rebase-continue.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ test_expect_success 'there is no --no-reschedule-failed-exec in an ongoing rebas
328328
test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec
329329
'
330330

331-
test_expect_success 'no change in comment character due to conflicts markers with core.commentChar=auto' '
331+
test_expect_success !WITH_BREAKING_CHANGES 'no change in comment character due to conflicts markers with core.commentChar=auto' '
332332
git checkout -b branch-a &&
333333
test_commit A F1 &&
334334
git checkout -b branch-b HEAD^ &&

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)