Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit a495281

Browse files
Andrew Pimlottgitster
authored andcommitted
lib-rebase: style: use write_script, <<-\EOF
Signed-off-by: Andrew Pimlott <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 22c5b13 commit a495281

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

t/lib-rebase.sh

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,48 +22,46 @@
2222
# ">" -- Add a blank line.
2323

2424
set_fake_editor () {
25-
echo "#!$SHELL_PATH" >fake-editor.sh
26-
cat >> fake-editor.sh <<\EOF
27-
case "$1" in
28-
*/COMMIT_EDITMSG)
29-
test -z "$EXPECT_HEADER_COUNT" ||
30-
test "$EXPECT_HEADER_COUNT" = "$(sed -n '1s/^# This is a combination of \(.*\) commits\./\1/p' < "$1")" ||
25+
write_script fake-editor.sh <<-\EOF
26+
case "$1" in
27+
*/COMMIT_EDITMSG)
28+
test -z "$EXPECT_HEADER_COUNT" ||
29+
test "$EXPECT_HEADER_COUNT" = "$(sed -n '1s/^# This is a combination of \(.*\) commits\./\1/p' < "$1")" ||
30+
exit
31+
test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
32+
test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"
3133
exit
32-
test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
33-
test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"
34-
exit
35-
;;
36-
esac
37-
test -z "$EXPECT_COUNT" ||
38-
test "$EXPECT_COUNT" = $(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l) ||
39-
exit
40-
test -z "$FAKE_LINES" && exit
41-
grep -v '^#' < "$1" > "$1".tmp
42-
rm -f "$1"
43-
echo 'rebase -i script before editing:'
44-
cat "$1".tmp
45-
action=pick
46-
for line in $FAKE_LINES; do
47-
case $line in
48-
squash|fixup|edit|reword)
49-
action="$line";;
50-
exec*)
51-
echo "$line" | sed 's/_/ /g' >> "$1";;
52-
"#")
53-
echo '# comment' >> "$1";;
54-
">")
55-
echo >> "$1";;
56-
*)
57-
sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1"
58-
action=pick;;
34+
;;
5935
esac
60-
done
61-
echo 'rebase -i script after editing:'
62-
cat "$1"
63-
EOF
36+
test -z "$EXPECT_COUNT" ||
37+
test "$EXPECT_COUNT" = $(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l) ||
38+
exit
39+
test -z "$FAKE_LINES" && exit
40+
grep -v '^#' < "$1" > "$1".tmp
41+
rm -f "$1"
42+
echo 'rebase -i script before editing:'
43+
cat "$1".tmp
44+
action=pick
45+
for line in $FAKE_LINES; do
46+
case $line in
47+
squash|fixup|edit|reword)
48+
action="$line";;
49+
exec*)
50+
echo "$line" | sed 's/_/ /g' >> "$1";;
51+
"#")
52+
echo '# comment' >> "$1";;
53+
">")
54+
echo >> "$1";;
55+
*)
56+
sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1"
57+
action=pick;;
58+
esac
59+
done
60+
echo 'rebase -i script after editing:'
61+
cat "$1"
62+
EOF
6463

6564
test_set_editor "$(pwd)/fake-editor.sh"
66-
chmod a+x fake-editor.sh
6765
}
6866

6967
# After set_cat_todo_editor, rebase -i will write the todo list (ignoring

0 commit comments

Comments
 (0)