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