]>
Commit | Line | Data |
---|---|---|
29a03348 JS |
1 | #!/bin/sh |
2 | ||
03af0870 JS |
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 | |
05c95dbe MH |
8 | # - rewrite a rebase -i script as directed by $FAKE_LINES. |
9 | # $FAKE_LINES consists of a sequence of words separated by spaces. | |
10 | # The following word combinations are possible: | |
03af0870 | 11 | # |
05c95dbe MH |
12 | # "<lineno>" -- add a "pick" line with the SHA1 taken from the |
13 | # specified line. | |
03af0870 | 14 | # |
05c95dbe MH |
15 | # "<cmd> <lineno>" -- add a line with the specified command |
16 | # ("squash", "fixup", "edit", or "reword") and the SHA1 taken | |
17 | # from the specified line. | |
18 | # | |
19 | # "#" -- Add a comment line. | |
20 | # | |
21 | # ">" -- Add a blank line. | |
03af0870 | 22 | |
29a03348 JS |
23 | set_fake_editor () { |
24 | echo "#!$SHELL_PATH" >fake-editor.sh | |
25 | cat >> fake-editor.sh <<\EOF | |
26 | case "$1" in | |
27 | */COMMIT_EDITMSG) | |
28 | test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1" | |
29 | test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1" | |
30 | exit | |
31 | ;; | |
32 | esac | |
33 | test -z "$EXPECT_COUNT" || | |
34 | test "$EXPECT_COUNT" = $(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l) || | |
35 | exit | |
36 | test -z "$FAKE_LINES" && exit | |
37 | grep -v '^#' < "$1" > "$1".tmp | |
38 | rm -f "$1" | |
f64b4856 | 39 | echo 'rebase -i script before editing:' |
29a03348 JS |
40 | cat "$1".tmp |
41 | action=pick | |
42 | for line in $FAKE_LINES; do | |
43 | case $line in | |
0205e72f | 44 | squash|fixup|edit|reword) |
29a03348 | 45 | action="$line";; |
05c95dbe MH |
46 | "#") |
47 | echo '# comment' >> "$1";; | |
48 | ">") | |
49 | echo >> "$1";; | |
29a03348 | 50 | *) |
29a03348 JS |
51 | sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1" |
52 | action=pick;; | |
53 | esac | |
54 | done | |
f64b4856 MH |
55 | echo 'rebase -i script after editing:' |
56 | cat "$1" | |
29a03348 JS |
57 | EOF |
58 | ||
59 | test_set_editor "$(pwd)/fake-editor.sh" | |
60 | chmod a+x fake-editor.sh | |
61 | } |