Skip to content

Commit bd53f38

Browse files
committed
Merge branch 'js/rebase-i-commentchar-fix'
"git rebase -i" did not work well with core.commentchar configuration variable for two reasons, both of which have been fixed. * js/rebase-i-commentchar-fix: rebase -i: handle core.commentChar=auto stripspace: respect repository config rebase -i: highlight problems with core.commentchar
2 parents 48e9ad5 + 882cd23 commit bd53f38

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

builtin/stripspace.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
4444
if (argc)
4545
usage_with_options(stripspace_usage, options);
4646

47-
if (mode == STRIP_COMMENTS || mode == COMMENT_LINES)
47+
if (mode == STRIP_COMMENTS || mode == COMMENT_LINES) {
48+
setup_git_directory_gently(NULL);
4849
git_config(git_default_config, NULL);
50+
}
4951

5052
if (strbuf_read(&buf, 0, 1024) < 0)
5153
die_errno("could not read the input");

git-rebase--interactive.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,17 @@ eval '
9393
GIT_CHERRY_PICK_HELP="$resolvemsg"
9494
export GIT_CHERRY_PICK_HELP
9595

96-
comment_char=$(git config --get core.commentchar 2>/dev/null | cut -c1)
97-
: ${comment_char:=#}
96+
comment_char=$(git config --get core.commentchar 2>/dev/null)
97+
case "$comment_char" in
98+
'' | auto)
99+
comment_char="#"
100+
;;
101+
?)
102+
;;
103+
*)
104+
comment_char=$(echo "$comment_char" | cut -c1)
105+
;;
106+
esac
98107

99108
warn () {
100109
printf '%s\n' "$*" >&2

t/t0030-stripspace.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,15 @@ test_expect_success '-c with changed comment char' '
432432
test_cmp expect actual
433433
'
434434

435+
test_expect_success '-c with comment char defined in .git/config' '
436+
test_config core.commentchar = &&
437+
printf "= foo\n" >expect &&
438+
printf "foo" | (
439+
mkdir sub && cd sub && git stripspace -c
440+
) >actual &&
441+
test_cmp expect actual
442+
'
443+
435444
test_expect_success 'avoid SP-HT sequence in commented line' '
436445
printf "#\tone\n#\n# two\n" >expect &&
437446
printf "\tone\n\ntwo\n" | git stripspace -c >actual &&

t/t3404-rebase-interactive.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,17 @@ test_expect_success 'rebase -i respects core.commentchar' '
976976
test B = $(git cat-file commit HEAD^ | sed -ne \$p)
977977
'
978978

979+
test_expect_success 'rebase -i respects core.commentchar=auto' '
980+
test_config core.commentchar auto &&
981+
write_script copy-edit-script.sh <<-\EOF &&
982+
cp "$1" edit-script
983+
EOF
984+
test_set_editor "$(pwd)/copy-edit-script.sh" &&
985+
test_when_finished "git rebase --abort || :" &&
986+
git rebase -i HEAD^ &&
987+
test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
988+
'
989+
979990
test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
980991
test_when_finished "git branch -D torebase" &&
981992
git checkout -b torebase branch1 &&

0 commit comments

Comments
 (0)