@@ -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 () {
@@ -363,10 +366,10 @@ update_squash_messages () {
363366 if test -f " $squash_msg " ; then
364367 mv " $squash_msg " " $squash_msg " .bak || exit
365368 count=$(( $(sed - n \
366- -e "1 s/^# This is a combination of \(.*\) commits\./\1 /p" \
369+ -e "1 s/^. This is a combination of \(.*\) commits\./\1 /p" \
367370 -e "q" < "$squash_msg ".bak)+1 ))
368371 {
369- echo " # This is a combination of $count commits."
372+ printf ' %s\n ' " $comment_char This is a combination of $count commits."
370373 sed -e 1d -e ' 2,/^./{
371374 /^$/d
372375 }' < " $squash_msg " .bak
@@ -375,8 +378,8 @@ update_squash_messages () {
375378 commit_message HEAD > " $fixup_msg " || die " Cannot write $fixup_msg "
376379 count=2
377380 {
378- echo " # This is a combination of 2 commits."
379- echo " # The first commit's message is:"
381+ printf ' %s\n ' " $comment_char This is a combination of 2 commits."
382+ printf ' %s\n ' " $comment_char The first commit's message is:"
380383 echo
381384 cat " $fixup_msg "
382385 } > " $squash_msg "
@@ -385,21 +388,22 @@ update_squash_messages () {
385388 squash)
386389 rm -f " $fixup_msg "
387390 echo
388- echo " # This is the $( nth_string $count ) commit message:"
391+ printf ' %s\n ' " $comment_char This is the $( nth_string $count ) commit message:"
389392 echo
390393 commit_message $2
391394 ;;
392395 fixup)
393396 echo
394- echo " # The $( nth_string $count ) commit message will be skipped:"
397+ printf ' %s\n ' " $comment_char The $( nth_string $count ) commit message will be skipped:"
395398 echo
396- commit_message $2 | sed -e ' s/^/# /'
399+ # Change the space after the comment character to TAB:
400+ commit_message $2 | git stripspace --comment-lines | sed -e ' s/ / /'
397401 ;;
398402 esac >> " $squash_msg "
399403}
400404
401405peek_next_command () {
402- sed -n -e " /^#/d " -e ' /^$/d ' -e " s/ .*//p" -e " q " < " $todo "
406+ git stripspace --strip-comments < " $todo " | sed -n -e ' s/ .*//p' -e q
403407}
404408
405409# A squash/fixup has failed. Prepare the long version of the squash
@@ -464,7 +468,7 @@ do_next () {
464468 rm -f " $msg " " $author_script " " $amend " || exit
465469 read -r command sha1 rest < " $todo "
466470 case " $command " in
467- ' # ' * |' ' |noop)
471+ " $comment_char " * |' ' |noop)
468472 mark_action_done
469473 ;;
470474 pick|p)
@@ -803,15 +807,15 @@ skip)
803807 do_rest
804808 ;;
805809edit-todo)
806- sed -e ' /^#/d ' < " $todo " > " $todo " .new
810+ git stripspace --strip-comments < " $todo " > " $todo " .new
807811 mv -f " $todo " .new " $todo "
808812 append_todo_help
809- cat >> " $todo " << EOF
810- #
811- # You are editing the todo file of an ongoing interactive rebase.
812- # To continue rebase after editing, run:
813- # git rebase --continue
814- #
813+ git stripspace --comment-lines >> " $todo " << \ EOF
814+
815+ You are editing the todo file of an ongoing interactive rebase.
816+ To continue rebase after editing, run:
817+ git rebase --continue
818+
815819EOF
816820
817821 git_sequence_editor " $todo " ||
881885
882886 if test -z " $keep_empty " && is_empty_commit $shortsha1 && ! is_merge_commit $shortsha1
883887 then
884- comment_out=" # "
888+ comment_out=" $comment_char "
885889 else
886890 comment_out=
887891 fi
@@ -942,20 +946,20 @@ test -s "$todo" || echo noop >> "$todo"
942946test -n " $autosquash " && rearrange_squash " $todo "
943947test -n " $cmd " && add_exec_commands " $todo "
944948
945- cat >> " $todo " << EOF
949+ cat >> " $todo " << EOF
946950
947- # Rebase $shortrevisions onto $shortonto
951+ $comment_char Rebase $shortrevisions onto $shortonto
948952EOF
949953append_todo_help
950- cat >> " $todo " << EOF
951- #
952- # However, if you remove everything, the rebase will be aborted.
953- #
954+ git stripspace --comment-lines >> " $todo " << \ EOF
955+
956+ However, if you remove everything, the rebase will be aborted.
957+
954958EOF
955959
956960if test -z " $keep_empty "
957961then
958- echo " # Note that empty commits are commented out" >> " $todo "
962+ printf ' %s\n ' " $comment_char Note that empty commits are commented out" >> " $todo "
959963fi
960964
961965
0 commit comments