1#!/bin/sh 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", or "reword") and the SHA1 taken 18# from the specified line. 19# 20# "#" -- Add a comment line. 21# 22# ">" -- Add a blank line. 23 24set_fake_editor () { 25 write_script fake-editor.sh <<-\EOF 26case"$1"in 27*/COMMIT_EDITMSG) 28test -z"$EXPECT_HEADER_COUNT"|| 29test"$EXPECT_HEADER_COUNT"="$(sed -n '1s/^# This is a combination of \(.*\)commits\./\1/p' < "$1")"|| 30exit 31test -z"$FAKE_COMMIT_MESSAGE"||echo"$FAKE_COMMIT_MESSAGE">"$1" 32test -z"$FAKE_COMMIT_AMEND"||echo"$FAKE_COMMIT_AMEND">>"$1" 33exit 34;; 35esac 36test -z"$EXPECT_COUNT"|| 37test"$EXPECT_COUNT"=$(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l)|| 38exit 39test -z"$FAKE_LINES"&&exit 40grep-v'^#'<"$1">"$1".tmp 41rm-f"$1" 42echo'rebase -i script before editing:' 43cat"$1".tmp 44 action=pick 45for line in$FAKE_LINES;do 46case$linein 47 squash|fixup|edit|reword) 48 action="$line";; 49exec*) 50echo"$line"|sed's/_/ /g'>>"$1";; 51"#") 52echo'# comment'>>"$1";; 53">") 54echo>>"$1";; 55*) 56sed-n"${line}s/^pick/$action/p"<"$1".tmp >>"$1" 57 action=pick;; 58esac 59done 60echo'rebase -i script after editing:' 61cat"$1" 62 EOF 63 64 test_set_editor "$(pwd)/fake-editor.sh" 65} 66 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. 72 73set_cat_todo_editor () { 74 write_script fake-editor.sh <<-\EOF 75grep"^[^#]""$1" 76exit1 77 EOF 78 test_set_editor "$(pwd)/fake-editor.sh" 79} 80 81# checks that the revisions in "$2" represent a linear range with the 82# subjects in "$1" 83test_linear_range () { 84 revlist_merges=$(git rev-list --merges "$2")&& 85test -z"$revlist_merges"&& 86 expected=$1 87set --$(git log --reverse --format=%s "$2") 88test"$expected"="$*" 89} 90 91reset_rebase () { 92 test_might_fail git rebase --abort&& 93 git reset--hard&& 94 git clean -f 95} 96 97cherry_pick () { 98 git cherry-pick -n"$2"&& 99 git commit -m"$1"&& 100 git tag "$1" 101} 102 103revert () { 104 git revert -n"$2"&& 105 git commit -m"$1"&& 106 git tag "$1" 107} 108 109make_empty () { 110 git commit --allow-empty -m"$1"&& 111 git tag "$1" 112}