@@ -80,6 +80,9 @@ rewritten_pending="$state_dir"/rewritten-pending
8080GIT_CHERRY_PICK_HELP=" $resolvemsg "
8181export GIT_CHERRY_PICK_HELP
8282
83+ comment_char=$( git config --get core.commentchar 2> /dev/null | cut -c1)
84+ : ${comment_char:=# }
85+
8386warn () {
8487 printf ' %s\n' " $* " >&2
8588}
@@ -105,8 +108,8 @@ mark_action_done () {
105108 sed -e 1q < " $todo " >> " $done "
106109 sed -e 1d < " $todo " >> " $todo " .new
107110 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 )) )
110113 if test " $last_count " ! = " $new_count "
111114 then
112115 last_count=$new_count
@@ -116,19 +119,19 @@ mark_action_done () {
116119}
117120
118121append_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.
132135EOF
133136}
134137
@@ -179,7 +182,7 @@ die_abort () {
179182}
180183
181184has_action () {
182- sane_grep ' ^[^#] ' " $1 " > /dev/null
185+ test -n " $( git stripspace --strip-comments < " $1 " ) "
183186}
184187
185188is_empty_commit () {
@@ -358,10 +361,10 @@ update_squash_messages () {
358361 if test -f " $squash_msg " ; then
359362 mv " $squash_msg " " $squash_msg " .bak || exit
360363 count=$(( $(sed - n \
361- -e "1 s/^# This is a combination of \(.*\) commits\./\1 /p" \
364+ -e "1 s/^. This is a combination of \(.*\) commits\./\1 /p" \
362365 -e "q" < "$squash_msg ".bak)+1 ))
363366 {
364- echo " # This is a combination of $count commits."
367+ printf ' %s\n ' " $comment_char This is a combination of $count commits."
365368 sed -e 1d -e ' 2,/^./{
366369 /^$/d
367370 }' < " $squash_msg " .bak
@@ -370,8 +373,8 @@ update_squash_messages () {
370373 commit_message HEAD > " $fixup_msg " || die " Cannot write $fixup_msg "
371374 count=2
372375 {
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:"
375378 echo
376379 cat " $fixup_msg "
377380 } > " $squash_msg "
@@ -380,21 +383,22 @@ update_squash_messages () {
380383 squash)
381384 rm -f " $fixup_msg "
382385 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:"
384387 echo
385388 commit_message $2
386389 ;;
387390 fixup)
388391 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:"
390393 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/ / /'
392396 ;;
393397 esac >> " $squash_msg "
394398}
395399
396400peek_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
398402}
399403
400404# A squash/fixup has failed. Prepare the long version of the squash
@@ -459,7 +463,7 @@ do_next () {
459463 rm -f " $msg " " $author_script " " $amend " || exit
460464 read -r command sha1 rest < " $todo "
461465 case " $command " in
462- ' # ' * |' ' |noop)
466+ " $comment_char " * |' ' |noop)
463467 mark_action_done
464468 ;;
465469 pick|p)
@@ -798,15 +802,15 @@ skip)
798802 do_rest
799803 ;;
800804edit-todo)
801- sed -e ' /^#/d ' < " $todo " > " $todo " .new
805+ git stripspace --strip-comments < " $todo " > " $todo " .new
802806 mv -f " $todo " .new " $todo "
803807 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+
810814EOF
811815
812816 git_sequence_editor " $todo " ||
876880
877881 if test -z " $keep_empty " && is_empty_commit $shortsha1
878882 then
879- comment_out=" # "
883+ comment_out=" $comment_char "
880884 else
881885 comment_out=
882886 fi
@@ -937,20 +941,20 @@ test -s "$todo" || echo noop >> "$todo"
937941test -n " $autosquash " && rearrange_squash " $todo "
938942test -n " $cmd " && add_exec_commands " $todo "
939943
940- cat >> " $todo " << EOF
944+ cat >> " $todo " << EOF
941945
942- # Rebase $shortrevisions onto $shortonto
946+ $comment_char Rebase $shortrevisions onto $shortonto
943947EOF
944948append_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+
949953EOF
950954
951955if test -z " $keep_empty "
952956then
953- echo " # Note that empty commits are commented out" >> " $todo "
957+ printf ' %s\n ' " $comment_char Note that empty commits are commented out" >> " $todo "
954958fi
955959
956960
0 commit comments