rebase -i: respect core.commentchar

Commit eff80a9 (Allow custom "comment char") introduced a custom comment character for commit messages but did not teach git-rebase--interactive to use it. Change git-rebase--interactive to read core.commentchar and use its value when generating commit messages and for the command list. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

John Keeping committed Feb 11, 2013 at 23:08 UTC 180bad3d10fe3a7f6d6c990956a888dd0562bef1
2 files changed +58 -40
git-rebase--interactive.sh
+44 -40
@@ -80,6 +80,9 @@ rewritten_pending="$state_dir"/rewritten-pending
80 GIT_CHERRY_PICK_HELP="$resolvemsg"
81 export GIT_CHERRY_PICK_HELP
82
83 +comment_char=$(git config --get core.commentchar 2>/dev/null | cut -c1)
84 +: ${comment_char:=#}
85 +
86 warn () {
87 printf '%s\n' "$*" >&2
88 }
@@ -105,8 +108,8 @@ mark_action_done () {
108 sed -e 1q < "$todo" >> "$done"
109 sed -e 1d < "$todo" >> "$todo".new
110 mv -f "$todo".new "$todo"
108 - new_count=$(sane_grep -c '^[^#]' < "$done")
109 - total=$(($new_count+$(sane_grep -c '^[^#]' < "$todo")))
111 + new_count=$(git stripspace --strip-comments <"$done" | wc -l)
112 + total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
113 if test "$last_count" != "$new_count"
114 then
115 last_count=$new_count
@@ -116,19 +119,19 @@ mark_action_done () {
119 }
120
121 append_todo_help () {
119 - cat >> "$todo" << EOF
120 -#
121 -# Commands:
122 -# p, pick = use commit
123 -# r, reword = use commit, but edit the commit message
124 -# e, edit = use commit, but stop for amending
125 -# s, squash = use commit, but meld into previous commit
126 -# f, fixup = like "squash", but discard this commit's log message
127 -# x, exec = run command (the rest of the line) using shell
128 -#
129 -# These lines can be re-ordered; they are executed from top to bottom.
130 -#
131 -# If you remove a line here THAT COMMIT WILL BE LOST.
122 + git stripspace --comment-lines >>"$todo" <<\EOF
123 +
124 +Commands:
125 + p, pick = use commit
126 + r, reword = use commit, but edit the commit message
127 + e, edit = use commit, but stop for amending
128 + s, squash = use commit, but meld into previous commit
129 + f, fixup = like "squash", but discard this commit's log message
130 + x, exec = run command (the rest of the line) using shell
131 +
132 +These lines can be re-ordered; they are executed from top to bottom.
133 +
134 +If you remove a line here THAT COMMIT WILL BE LOST.
135 EOF
136 }
137
@@ -179,7 +182,7 @@ die_abort () {
182 }
183
184 has_action () {
182 - sane_grep '^[^#]' "$1" >/dev/null
185 + test -n "$(git stripspace --strip-comments <"$1")"
186 }
187
188 is_empty_commit() {
@@ -358,10 +361,10 @@ update_squash_messages () {
361 if test -f "$squash_msg"; then
362 mv "$squash_msg" "$squash_msg".bak || exit
363 count=$(($(sed -n \
361 - -e "1s/^# This is a combination of \(.*\) commits\./\1/p" \
364 + -e "1s/^. This is a combination of \(.*\) commits\./\1/p" \
365 -e "q" < "$squash_msg".bak)+1))
366 {
364 - echo "# This is a combination of $count commits."
367 + printf '%s\n' "$comment_char This is a combination of $count commits."
368 sed -e 1d -e '2,/^./{
369 /^$/d
370 }' <"$squash_msg".bak
@@ -370,8 +373,8 @@ update_squash_messages () {
373 commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg"
374 count=2
375 {
373 - echo "# This is a combination of 2 commits."
374 - echo "# The first commit's message is:"
376 + printf '%s\n' "$comment_char This is a combination of 2 commits."
377 + printf '%s\n' "$comment_char The first commit's message is:"
378 echo
379 cat "$fixup_msg"
380 } >"$squash_msg"
@@ -380,21 +383,22 @@ update_squash_messages () {
383 squash)
384 rm -f "$fixup_msg"
385 echo
383 - echo "# This is the $(nth_string $count) commit message:"
386 + printf '%s\n' "$comment_char This is the $(nth_string $count) commit message:"
387 echo
388 commit_message $2
389 ;;
390 fixup)
391 echo
389 - echo "# The $(nth_string $count) commit message will be skipped:"
392 + printf '%s\n' "$comment_char The $(nth_string $count) commit message will be skipped:"
393 echo
391 - commit_message $2 | sed -e 's/^/# /'
394 + # Change the space after the comment character to TAB:
395 + commit_message $2 | git stripspace --comment-lines | sed -e 's/ / /'
396 ;;
397 esac >>"$squash_msg"
398 }
399
400 peek_next_command () {
397 - sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$todo"
401 + git stripspace --strip-comments <"$todo" | sed -n -e 's/ .*//p' -e q
402 }
403
404 # A squash/fixup has failed. Prepare the long version of the squash
@@ -459,7 +463,7 @@ do_next () {
463 rm -f "$msg" "$author_script" "$amend" || exit
464 read -r command sha1 rest < "$todo"
465 case "$command" in
462 - '#'*|''|noop)
466 + "$comment_char"*|''|noop)
467 mark_action_done
468 ;;
469 pick|p)
@@ -798,15 +802,15 @@ skip)
802 do_rest
803 ;;
804 edit-todo)
801 - sed -e '/^#/d' < "$todo" > "$todo".new
805 + git stripspace --strip-comments <"$todo" >"$todo".new
806 mv -f "$todo".new "$todo"
807 append_todo_help
804 - cat >> "$todo" << EOF
805 -#
806 -# You are editing the todo file of an ongoing interactive rebase.
807 -# To continue rebase after editing, run:
808 -# git rebase --continue
809 -#
808 + git stripspace --comment-lines >>"$todo" <<\EOF
809 +
810 +You are editing the todo file of an ongoing interactive rebase.
811 +To continue rebase after editing, run:
812 + git rebase --continue
813 +
814 EOF
815
816 git_sequence_editor "$todo" ||
@@ -876,7 +880,7 @@ do
880
881 if test -z "$keep_empty" && is_empty_commit $shortsha1
882 then
879 - comment_out="# "
883 + comment_out="$comment_char "
884 else
885 comment_out=
886 fi
@@ -937,20 +941,20 @@ test -s "$todo" || echo noop >> "$todo"
941 test -n "$autosquash" && rearrange_squash "$todo"
942 test -n "$cmd" && add_exec_commands "$todo"
943
940 -cat >> "$todo" << EOF
944 +cat >>"$todo" <<EOF
945
942 -# Rebase $shortrevisions onto $shortonto
946 +$comment_char Rebase $shortrevisions onto $shortonto
947 EOF
948 append_todo_help
945 -cat >> "$todo" << EOF
946 -#
947 -# However, if you remove everything, the rebase will be aborted.
948 -#
949 +git stripspace --comment-lines >>"$todo" <<\EOF
950 +
951 +However, if you remove everything, the rebase will be aborted.
952 +
953 EOF
954
955 if test -z "$keep_empty"
956 then
953 - echo "# Note that empty commits are commented out" >>"$todo"
957 + printf '%s\n' "$comment_char Note that empty commits are commented out" >>"$todo"
958 fi
959
960
t/t3404-rebase-interactive.sh
+14
@@ -940,4 +940,18 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' '
940 test L = $(git cat-file commit HEAD | sed -ne \$p)
941 '
942
943 +test_expect_success 'rebase -i respects core.commentchar' '
944 + git reset --hard &&
945 + git checkout E^0 &&
946 + git config core.commentchar "\\" &&
947 + test_when_finished "git config --unset core.commentchar" &&
948 + write_script remove-all-but-first.sh <<-\EOF &&
949 + sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
950 + mv "$1.tmp" "$1"
951 + EOF
952 + test_set_editor "$(pwd)/remove-all-but-first.sh" &&
953 + git rebase -i B &&
954 + test B = $(git cat-file commit HEAD^ | sed -ne \$p)
955 +'
956 +
957 test_done