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