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 # - check the commit count in the commit message header with $EXPECT_HEADER_COUNT
9 # - rewrite a rebase -i script as directed by $FAKE_LINES.
10 # $FAKE_LINES consists of a sequence of words separated by spaces.
11 # The following word combinations are possible:
13 # "<lineno>" -- add a "pick" line with the SHA1 taken from the
16 # "<cmd> <lineno>" -- add a line with the specified command
17 # ("squash", "fixup", "edit", or "reword") and the SHA1 taken
18 # from the specified line.
20 # "#" -- Add a comment line.
22 # ">" -- Add a blank line.
25 write_script fake-editor.sh
<<-\EOF
28 test -z "$EXPECT_HEADER_COUNT" ||
29 test "$EXPECT_HEADER_COUNT" = "$(sed -n '1s/^# This is a combination of \(.*\) commits\./\1/p' < "$1")" ||
31 test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
32 test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"
36 test -z "$EXPECT_COUNT" ||
37 test "$EXPECT_COUNT" = $(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l) ||
39 test -z "$FAKE_LINES" && exit
40 grep -v '^#' < "$1" > "$1".tmp
42 echo 'rebase -i script before editing:'
45 for line in $FAKE_LINES; do
47 squash|fixup|edit|reword)
50 echo "$line" | sed 's/_/ /g' >> "$1";;
52 echo '# comment' >> "$1";;
56 sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1"
60 echo 'rebase -i script after editing:'
64 test_set_editor "$(pwd)/fake-editor.sh"
67 # After set_cat_todo_editor, rebase -i will write the todo list (ignoring
68 # blank lines and comments) to stdout, and exit failure (so you should run
69 # it with test_must_fail). This can be used to verify the expected user
70 # experience, for todo list changes that do not affect the outcome of
71 # rebase; or as an extra check in addition to checking the outcome.
73 set_cat_todo_editor () {
74 write_script fake-editor.sh <<-\
EOF
78 test_set_editor "$(pwd)/fake-editor.sh"
81 # checks that the revisions in "$2" represent a linear range with the
83 test_linear_range () {
84 revlist_merges=$(git rev-list --merges "$2") &&
85 test -z "$revlist_merges" &&
87 set -- $(git log --reverse --format=%s "$2")
88 test "$expected" = "$*"
92 test_might_fail git rebase --abort &&
98 git cherry-pick -n "$2" &&
104 git revert -n "$2" &&
105 git commit -m "$1" &&
110 git commit --allow-empty -m "$1" &&