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