gitweb: Make 'history' view (re)use git_log_generic()
[git/gsoc2010-gitweb.git] / t / lib-rebase.sh
blob62f452c8ea2c2718fff300d39531fbc4c2e6a44a
1 #!/bin/sh
3 # After setting the fake editor with this function, you can
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
10 # "[<lineno1>] [<lineno2>]..."
12 # If a line number is prefixed with "squash", "edit", or "reword", the
13 # respective line's command will be replaced with the specified one.
15 set_fake_editor () {
16 echo "#!$SHELL_PATH" >fake-editor.sh
17 cat >> fake-editor.sh <<\EOF
18 case "$1" in
19 */COMMIT_EDITMSG)
20 test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
21 test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"
22 exit
24 esac
25 test -z "$EXPECT_COUNT" ||
26 test "$EXPECT_COUNT" = $(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l) ||
27 exit
28 test -z "$FAKE_LINES" && exit
29 grep -v '^#' < "$1" > "$1".tmp
30 rm -f "$1"
31 cat "$1".tmp
32 action=pick
33 for line in $FAKE_LINES; do
34 case $line in
35 squash|edit|reword)
36 action="$line";;
38 echo sed -n "${line}s/^pick/$action/p"
39 sed -n "${line}p" < "$1".tmp
40 sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1"
41 action=pick;;
42 esac
43 done
44 EOF
46 test_set_editor "$(pwd)/fake-editor.sh"
47 chmod a+x fake-editor.sh