Skip to content

Commit 938791c

Browse files
drafnelgitster
authored andcommitted
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 <[email protected]> Acked-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec13666 commit 938791c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

git-rebase--interactive.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ run 'git rebase --continue'"
119119
export GIT_CHERRY_PICK_HELP
120120

121121
warn () {
122-
echo "$*" >&2
122+
printf '%s\n' "$*" >&2
123123
}
124124

125125
output () {
@@ -606,7 +606,7 @@ skip_unnecessary_picks () {
606606
fd=1
607607
;;
608608
esac
609-
echo "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd
609+
printf '%s\n' "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd
610610
done <"$TODO" >"$TODO.new" 3>>"$DONE" &&
611611
mv -f "$TODO".new "$TODO" &&
612612
case "$(peek_next_command)" in
@@ -649,12 +649,12 @@ rearrange_squash () {
649649
case " $used" in
650650
*" $sha1 "*) continue ;;
651651
esac
652-
echo "$pick $sha1 $message"
652+
printf '%s\n' "$pick $sha1 $message"
653653
while read -r squash action msg
654654
do
655655
case "$message" in
656656
"$msg"*)
657-
echo "$action $squash $action! $msg"
657+
printf '%s\n' "$action $squash $action! $msg"
658658
used="$used$squash "
659659
;;
660660
esac
@@ -895,7 +895,7 @@ first and then run 'git rebase --continue' again."
895895
do
896896
if test t != "$PRESERVE_MERGES"
897897
then
898-
echo "pick $shortsha1 $rest" >> "$TODO"
898+
printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
899899
else
900900
sha1=$(git rev-parse $shortsha1)
901901
if test -z "$REBASE_ROOT"
@@ -914,7 +914,7 @@ first and then run 'git rebase --continue' again."
914914
if test f = "$preserve"
915915
then
916916
touch "$REWRITTEN"/$sha1
917-
echo "pick $shortsha1 $rest" >> "$TODO"
917+
printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
918918
fi
919919
fi
920920
done

t/t3404-rebase-interactive.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,13 +637,19 @@ test_expect_success 'set up commits with funny messages' '
637637
git commit -a -m "end with slash\\" &&
638638
echo >>file1 &&
639639
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 &&
640646
git commit -a -m "another commit"
641647
'
642648

643649
test_expect_success 'rebase-i history with funny messages' '
644650
git rev-list A..funny >expect &&
645651
test_tick &&
646-
FAKE_LINES="1 2" git rebase -i A &&
652+
FAKE_LINES="1 2 3 4" git rebase -i A &&
647653
git rev-list A.. >actual &&
648654
test_cmp expect actual
649655
'

0 commit comments

Comments
 (0)