@matheusbsbs / matheus-bagliano / commits / 938791cd01
Fork 0

git-rebase--interactive.sh: use printf instead of echo to print commit message

On systems with an echo which defaults to the XSI-conformant behavior (Solaris, or others using Ksh), echo will interpret certain backslashed characters as control sequences. This can cause a problem for interactive rebase when it is used to rebase commits whose commit "subject" (the first line) contains any of these backslashed sequences. In this case, echo will substitute the control sequence for the backslashed characters and either the rebased commit message will differ from the original, or the rebase process will fail. Neither is desirable. So work around this issue by replacing the echo statements used to print out portions of the commit message, with printf. Also, add a test to test for this breakage. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Acked-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Jul 22, 2010 at 14:15 UTC 938791cd01bfb9729feed95a12f743fd077d0467
2 files changed +13 -7
git-rebase--interactive.sh
+6 -6
@@ -119,7 +119,7 @@ run 'git rebase --continue'"
119 export GIT_CHERRY_PICK_HELP
120
121 warn () {
122 - echo "$*" >&2
122 + printf '%s\n' "$*" >&2
123 }
124
125 output () {
@@ -606,7 +606,7 @@ skip_unnecessary_picks () {
606 fd=1
607 ;;
608 esac
609 - echo "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd
609 + printf '%s\n' "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd
610 done <"$TODO" >"$TODO.new" 3>>"$DONE" &&
611 mv -f "$TODO".new "$TODO" &&
612 case "$(peek_next_command)" in
@@ -649,12 +649,12 @@ rearrange_squash () {
649 case " $used" in
650 *" $sha1 "*) continue ;;
651 esac
652 - echo "$pick $sha1 $message"
652 + printf '%s\n' "$pick $sha1 $message"
653 while read -r squash action msg
654 do
655 case "$message" in
656 "$msg"*)
657 - echo "$action $squash $action! $msg"
657 + printf '%s\n' "$action $squash $action! $msg"
658 used="$used$squash "
659 ;;
660 esac
@@ -895,7 +895,7 @@ first and then run 'git rebase --continue' again."
895 do
896 if test t != "$PRESERVE_MERGES"
897 then
898 - echo "pick $shortsha1 $rest" >> "$TODO"
898 + printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
899 else
900 sha1=$(git rev-parse $shortsha1)
901 if test -z "$REBASE_ROOT"
@@ -914,7 +914,7 @@ first and then run 'git rebase --continue' again."
914 if test f = "$preserve"
915 then
916 touch "$REWRITTEN"/$sha1
917 - echo "pick $shortsha1 $rest" >> "$TODO"
917 + printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
918 fi
919 fi
920 done
t/t3404-rebase-interactive.sh
+7 -1
@@ -637,13 +637,19 @@ test_expect_success 'set up commits with funny messages' '
637 git commit -a -m "end with slash\\" &&
638 echo >>file1 &&
639 test_tick &&
640 + git commit -a -m "something (\000) that looks like octal" &&
641 + echo >>file1 &&
642 + test_tick &&
643 + git commit -a -m "something (\n) that looks like a newline" &&
644 + echo >>file1 &&
645 + test_tick &&
646 git commit -a -m "another commit"
647 '
648
649 test_expect_success 'rebase-i history with funny messages' '
650 git rev-list A..funny >expect &&
651 test_tick &&
646 - FAKE_LINES="1 2" git rebase -i A &&
652 + FAKE_LINES="1 2 3 4" git rebase -i A &&
653 git rev-list A.. >actual &&
654 test_cmp expect actual
655 '