Merge branch 'jk/rebase-i-comment-char'
authorJunio C Hamano <gitster@pobox.com>
Sun, 17 Feb 2013 23:25:19 +0000 (15:25 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 17 Feb 2013 23:25:20 +0000 (15:25 -0800)
Finishing touches to the earlier core.commentchar topic to cover
"rebase -i" as well.

* jk/rebase-i-comment-char:
rebase -i: respect core.commentchar

1  2 
git-rebase--interactive.sh
t/t3404-rebase-interactive.sh
index 8ed7fccc18507b6f3e2508bb117ce056a764de77,5db9e2d3f3666af232e7063bf2c46f3ea8ce79c1..048a140a6f6dd565a0d0d98b3b41439298626a96
@@@ -80,6 -80,9 +80,9 @@@ rewritten_pending="$state_dir"/rewritte
  GIT_CHERRY_PICK_HELP="$resolvemsg"
  export GIT_CHERRY_PICK_HELP
  
+ comment_char=$(git config --get core.commentchar 2>/dev/null | cut -c1)
+ : ${comment_char:=#}
  warn () {
        printf '%s\n' "$*" >&2
  }
@@@ -105,8 -108,8 +108,8 @@@ mark_action_done () 
        sed -e 1q < "$todo" >> "$done"
        sed -e 1d < "$todo" >> "$todo".new
        mv -f "$todo".new "$todo"
-       new_count=$(sane_grep -c '^[^#]' < "$done")
-       total=$(($new_count+$(sane_grep -c '^[^#]' < "$todo")))
+       new_count=$(git stripspace --strip-comments <"$done" | wc -l)
+       total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
        if test "$last_count" != "$new_count"
        then
                last_count=$new_count
  }
  
  append_todo_help () {
-       cat >> "$todo" << EOF
- #
Commands:
 p, pick = use commit
 r, reword = use commit, but edit the commit message
 e, edit = use commit, but stop for amending
 s, squash = use commit, but meld into previous commit
 f, fixup = like "squash", but discard this commit's log message
 x, exec = run command (the rest of the line) using shell
- #
These lines can be re-ordered; they are executed from top to bottom.
- #
If you remove a line here THAT COMMIT WILL BE LOST.
+       git stripspace --comment-lines >>"$todo" <<\EOF
+ Commands:
+  p, pick = use commit
+  r, reword = use commit, but edit the commit message
+  e, edit = use commit, but stop for amending
+  s, squash = use commit, but meld into previous commit
+  f, fixup = like "squash", but discard this commit's log message
+  x, exec = run command (the rest of the line) using shell
+ These lines can be re-ordered; they are executed from top to bottom.
+ If you remove a line here THAT COMMIT WILL BE LOST.
  EOF
  }
  
@@@ -179,7 -182,7 +182,7 @@@ die_abort () 
  }
  
  has_action () {
-       sane_grep '^[^#]' "$1" >/dev/null
+       test -n "$(git stripspace --strip-comments <"$1")"
  }
  
  is_empty_commit() {
        test "$tree" = "$ptree"
  }
  
 +is_merge_commit()
 +{
 +      git rev-parse --verify --quiet "$1"^2 >/dev/null 2>&1
 +}
 +
  # Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
  # GIT_AUTHOR_DATE exported from the current environment.
  do_with_author () {
@@@ -363,10 -361,10 +366,10 @@@ update_squash_messages () 
        if test -f "$squash_msg"; then
                mv "$squash_msg" "$squash_msg".bak || exit
                count=$(($(sed -n \
-                       -e "1s/^# This is a combination of \(.*\) commits\./\1/p" \
+                       -e "1s/^. This is a combination of \(.*\) commits\./\1/p" \
                        -e "q" < "$squash_msg".bak)+1))
                {
-                       echo "# This is a combination of $count commits."
+                       printf '%s\n' "$comment_char This is a combination of $count commits."
                        sed -e 1d -e '2,/^./{
                                /^$/d
                        }' <"$squash_msg".bak
                commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg"
                count=2
                {
-                       echo "# This is a combination of 2 commits."
-                       echo "# The first commit's message is:"
+                       printf '%s\n' "$comment_char This is a combination of 2 commits."
+                       printf '%s\n' "$comment_char The first commit's message is:"
                        echo
                        cat "$fixup_msg"
                } >"$squash_msg"
        squash)
                rm -f "$fixup_msg"
                echo
-               echo "# This is the $(nth_string $count) commit message:"
+               printf '%s\n' "$comment_char This is the $(nth_string $count) commit message:"
                echo
                commit_message $2
                ;;
        fixup)
                echo
-               echo "# The $(nth_string $count) commit message will be skipped:"
+               printf '%s\n' "$comment_char The $(nth_string $count) commit message will be skipped:"
                echo
-               commit_message $2 | sed -e 's/^/#       /'
+               # Change the space after the comment character to TAB:
+               commit_message $2 | git stripspace --comment-lines | sed -e 's/ /       /'
                ;;
        esac >>"$squash_msg"
  }
  
  peek_next_command () {
-       sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$todo"
+       git stripspace --strip-comments <"$todo" | sed -n -e 's/ .*//p' -e q
  }
  
  # A squash/fixup has failed.  Prepare the long version of the squash
@@@ -464,7 -463,7 +468,7 @@@ do_next () 
        rm -f "$msg" "$author_script" "$amend" || exit
        read -r command sha1 rest < "$todo"
        case "$command" in
-       '#'*|''|noop)
+       "$comment_char"*|''|noop)
                mark_action_done
                ;;
        pick|p)
@@@ -803,15 -802,15 +807,15 @@@ skip
        do_rest
        ;;
  edit-todo)
-       sed -e '/^#/d' < "$todo" > "$todo".new
+       git stripspace --strip-comments <"$todo" >"$todo".new
        mv -f "$todo".new "$todo"
        append_todo_help
-       cat >> "$todo" << EOF
- #
You are editing the todo file of an ongoing interactive rebase.
To continue rebase after editing, run:
    git rebase --continue
- #
+       git stripspace --comment-lines >>"$todo" <<\EOF
+ You are editing the todo file of an ongoing interactive rebase.
+ To continue rebase after editing, run:
+     git rebase --continue
  EOF
  
        git_sequence_editor "$todo" ||
@@@ -879,9 -878,9 +883,9 @@@ git rev-list $merges_option --pretty=on
  while read -r shortsha1 rest
  do
  
 -      if test -z "$keep_empty" && is_empty_commit $shortsha1
 +      if test -z "$keep_empty" && is_empty_commit $shortsha1 && ! is_merge_commit $shortsha1
        then
-               comment_out="# "
+               comment_out="$comment_char "
        else
                comment_out=
        fi
@@@ -942,20 -941,20 +946,20 @@@ test -s "$todo" || echo noop >> "$todo
  test -n "$autosquash" && rearrange_squash "$todo"
  test -n "$cmd" && add_exec_commands "$todo"
  
- cat >> "$todo" << EOF
+ cat >>"$todo" <<EOF
  
# Rebase $shortrevisions onto $shortonto
$comment_char Rebase $shortrevisions onto $shortonto
  EOF
  append_todo_help
cat >> "$todo" << EOF
- #
However, if you remove everything, the rebase will be aborted.
- #
git stripspace --comment-lines >>"$todo" <<\EOF
+ However, if you remove everything, the rebase will be aborted.
  EOF
  
  if test -z "$keep_empty"
  then
-       echo "# Note that empty commits are commented out" >>"$todo"
+       printf '%s\n' "$comment_char Note that empty commits are commented out" >>"$todo"
  fi
  
  
index 8462be1db6a0fe4f9e28cd1662be604196141055,8b3e2cdfac6354a8cc410ead8aeee6b90e0ce228..15dcbd42d367c3ef6b487e0f235ad201b6cf8413
@@@ -29,6 -29,12 +29,6 @@@ Initial setup
  
  . "$TEST_DIRECTORY"/lib-rebase.sh
  
 -test_cmp_rev () {
 -      git rev-parse --verify "$1" >expect.rev &&
 -      git rev-parse --verify "$2" >actual.rev &&
 -      test_cmp expect.rev actual.rev
 -}
 -
  set_fake_editor
  
  # WARNING: Modifications to the initial repository can change the SHA ID used
@@@ -934,4 -940,18 +934,18 @@@ test_expect_success 'rebase --edit-tod
        test L = $(git cat-file commit HEAD | sed -ne \$p)
  '
  
+ test_expect_success 'rebase -i respects core.commentchar' '
+       git reset --hard &&
+       git checkout E^0 &&
+       git config core.commentchar "\\" &&
+       test_when_finished "git config --unset core.commentchar" &&
+       write_script remove-all-but-first.sh <<-\EOF &&
+       sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
+       mv "$1.tmp" "$1"
+       EOF
+       test_set_editor "$(pwd)/remove-all-but-first.sh" &&
+       git rebase -i B &&
+       test B = $(git cat-file commit HEAD^ | sed -ne \$p)
+ '
  test_done