Add a command "fixup" to rebase --interactive
[git/mingw/j6t.git] / t / lib-rebase.sh
blobf4dda02b5ac70f5081f6cf9a35ef6dd8a5c254c3
1 #!/bin/sh
3 # After setting the fake editor with this function, you can
5 # - override the commit message with $FAKE_COMMIT_MESSAGE,
6 # - amend the commit message with $FAKE_COMMIT_AMEND
7 # - check that non-commit messages have a certain line count with $EXPECT_COUNT
8 # - rewrite a rebase -i script with $FAKE_LINES in the form
10 # "[<lineno1>] [<lineno2>]..."
12 # If a line number is prefixed with "squash", "fixup", "edit", or
13 # "reword", the respective line's command will be replaced with the
14 # specified one.
16 set_fake_editor () {
17 echo "#!$SHELL_PATH" >fake-editor.sh
18 cat >> fake-editor.sh <<\EOF
19 case "$1" in
20 */COMMIT_EDITMSG)
21 test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
22 test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"
23 exit
25 esac
26 test -z "$EXPECT_COUNT" ||
27 test "$EXPECT_COUNT" = $(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l) ||
28 exit
29 test -z "$FAKE_LINES" && exit
30 grep -v '^#' < "$1" > "$1".tmp
31 rm -f "$1"
32 cat "$1".tmp
33 action=pick
34 for line in $FAKE_LINES; do
35 case $line in
36 squash|fixup|edit|reword)
37 action="$line";;
39 echo sed -n "${line}s/^pick/$action/p"
40 sed -n "${line}p" < "$1".tmp
41 sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1"
42 action=pick;;
43 esac
44 done
45 EOF
47 test_set_editor "$(pwd)/fake-editor.sh"
48 chmod a+x fake-editor.sh