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# - rewrite a rebase -i script with $FAKE_LINES in the form 9# 10# "[<lineno1>] [<lineno2>]..." 11# 12# If a line number is prefixed with "squash", "fixup", "edit", or 13# "reword", the respective line's command will be replaced with the 14# specified one. 15 16set_fake_editor () { 17echo"#!$SHELL_PATH">fake-editor.sh 18cat>> fake-editor.sh <<\EOF 19case"$1"in 20*/COMMIT_EDITMSG) 21test -z"$FAKE_COMMIT_MESSAGE"||echo"$FAKE_COMMIT_MESSAGE">"$1" 22test -z"$FAKE_COMMIT_AMEND"||echo"$FAKE_COMMIT_AMEND">>"$1" 23exit 24;; 25esac 26test -z"$EXPECT_COUNT"|| 27test"$EXPECT_COUNT"=$(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l)|| 28exit 29test -z"$FAKE_LINES"&&exit 30grep-v'^#'<"$1">"$1".tmp 31rm-f"$1" 32echo'rebase -i script before editing:' 33cat"$1".tmp 34action=pick 35for line in$FAKE_LINES;do 36case$linein 37 squash|fixup|edit|reword) 38 action="$line";; 39*) 40sed-n"${line}s/^pick/$action/p"<"$1".tmp >>"$1" 41 action=pick;; 42esac 43done 44echo'rebase -i script after editing:' 45cat"$1" 46EOF 47 48 test_set_editor "$(pwd)/fake-editor.sh" 49chmod a+x fake-editor.sh 50}