1# Helper functions used by interactive rebase tests. 2 3# After setting the fake editor with this function, you can 4# 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: 12# 13# "<lineno>" -- add a "pick" line with the SHA1 taken from the 14# specified line. 15# 16# "<cmd> <lineno>" -- add a line with the specified command 17# ("pick", "squash", "fixup", "edit", "reword" or "drop") and the 18# SHA1 taken from the specified line. 19# 20# "exec_cmd_with_args" -- add an "exec cmd with args" line. 21# 22# "#" -- Add a comment line. 23# 24# ">" -- Add a blank line. 25 26set_fake_editor () { 27 write_script fake-editor.sh <<-\EOF 28case"$1"in 29*/COMMIT_EDITMSG) 30test -z"$EXPECT_HEADER_COUNT"|| 31test"$EXPECT_HEADER_COUNT"="$(sed -n '1s/^# This is a combination of \(.*\)commits\./\1/p' < "$1")"|| 32test"# # GETTEXT POISON #"="$(sed -n '1p' < "$1")"|| 33exit 34test -z"$FAKE_COMMIT_MESSAGE"||echo"$FAKE_COMMIT_MESSAGE">"$1" 35test -z"$FAKE_COMMIT_AMEND"||echo"$FAKE_COMMIT_AMEND">>"$1" 36exit 37;; 38esac 39test -z"$EXPECT_COUNT"|| 40test"$EXPECT_COUNT"=$(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l)|| 41exit 42test -z"$FAKE_LINES"&&exit 43grep-v'^#'<"$1">"$1".tmp 44rm-f"$1" 45echo'rebase -i script before editing:' 46cat"$1".tmp 47 action=pick 48for line in$FAKE_LINES;do 49case$linein 50 pick|squash|fixup|edit|reword|drop) 51 action="$line";; 52exec*) 53echo"$line"|sed's/_/ /g'>>"$1";; 54"#") 55echo'# comment'>>"$1";; 56">") 57echo>>"$1";; 58 bad) 59 action="badcmd";; 60 fakesha) 61echo"$actionXXXXXXX False commit">>"$1" 62 action=pick;; 63*) 64sed-n"${line}s/^pick/$action/p"<"$1".tmp >>"$1" 65 action=pick;; 66esac 67done 68echo'rebase -i script after editing:' 69cat"$1" 70 EOF 71 72 test_set_editor "$(pwd)/fake-editor.sh" 73} 74 75# After set_cat_todo_editor, rebase -i will write the todo list (ignoring 76# blank lines and comments) to stdout, and exit failure (so you should run 77# it with test_must_fail). This can be used to verify the expected user 78# experience, for todo list changes that do not affect the outcome of 79# rebase; or as an extra check in addition to checking the outcome. 80 81set_cat_todo_editor () { 82 write_script fake-editor.sh <<-\EOF 83grep"^[^#]""$1" 84exit1 85 EOF 86 test_set_editor "$(pwd)/fake-editor.sh" 87} 88 89# checks that the revisions in "$2" represent a linear range with the 90# subjects in "$1" 91test_linear_range () { 92 revlist_merges=$(git rev-list --merges "$2")&& 93test -z"$revlist_merges"&& 94 expected=$1 95set --$(git log --reverse --format=%s "$2") 96test"$expected"="$*" 97} 98 99reset_rebase () { 100 test_might_fail git rebase --abort&& 101 git reset--hard&& 102 git clean -f 103} 104 105cherry_pick () { 106 git cherry-pick -n"$2"&& 107 git commit -m"$1"&& 108 git tag "$1" 109} 110 111revert () { 112 git revert -n"$2"&& 113 git commit -m"$1"&& 114 git tag "$1" 115} 116 117make_empty () { 118 git commit --allow-empty -m"$1"&& 119 git tag "$1" 120}