]>
Commit | Line | Data |
---|---|---|
29a03348 JS |
1 | #!/bin/sh |
2 | ||
03af0870 JS |
3 | # After setting the fake editor with this function, you can |
4 | # | |
959c0d06 | 5 | # - override the commit message with $FAKE_COMMIT_MESSAGE |
03af0870 JS |
6 | # - amend the commit message with $FAKE_COMMIT_AMEND |
7 | # - check that non-commit messages have a certain line count with $EXPECT_COUNT | |
959c0d06 | 8 | # - check the commit count in the commit message header with $EXPECT_HEADER_COUNT |
05c95dbe MH |
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: | |
03af0870 | 12 | # |
05c95dbe MH |
13 | # "<lineno>" -- add a "pick" line with the SHA1 taken from the |
14 | # specified line. | |
03af0870 | 15 | # |
05c95dbe MH |
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. | |
03af0870 | 23 | |
29a03348 JS |
24 | set_fake_editor () { |
25 | echo "#!$SHELL_PATH" >fake-editor.sh | |
26 | cat >> fake-editor.sh <<\EOF | |
27 | case "$1" in | |
28 | */COMMIT_EDITMSG) | |
959c0d06 | 29 | test -z "$EXPECT_HEADER_COUNT" || |
30c9e919 | 30 | test "$EXPECT_HEADER_COUNT" = "$(sed -n '1s/^# This is a combination of \(.*\) commits\./\1/p' < "$1")" || |
959c0d06 | 31 | exit |
29a03348 JS |
32 | test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1" |
33 | test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1" | |
34 | exit | |
35 | ;; | |
36 | esac | |
37 | test -z "$EXPECT_COUNT" || | |
38 | test "$EXPECT_COUNT" = $(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l) || | |
39 | exit | |
40 | test -z "$FAKE_LINES" && exit | |
41 | grep -v '^#' < "$1" > "$1".tmp | |
42 | rm -f "$1" | |
f64b4856 | 43 | echo 'rebase -i script before editing:' |
29a03348 JS |
44 | cat "$1".tmp |
45 | action=pick | |
46 | for line in $FAKE_LINES; do | |
47 | case $line in | |
0205e72f | 48 | squash|fixup|edit|reword) |
29a03348 | 49 | action="$line";; |
cd035b1c MM |
50 | exec*) |
51 | echo "$line" | sed 's/_/ /g' >> "$1";; | |
05c95dbe MH |
52 | "#") |
53 | echo '# comment' >> "$1";; | |
54 | ">") | |
55 | echo >> "$1";; | |
29a03348 | 56 | *) |
29a03348 JS |
57 | sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1" |
58 | action=pick;; | |
59 | esac | |
60 | done | |
f64b4856 MH |
61 | echo 'rebase -i script after editing:' |
62 | cat "$1" | |
29a03348 JS |
63 | EOF |
64 | ||
65 | test_set_editor "$(pwd)/fake-editor.sh" | |
66 | chmod a+x fake-editor.sh | |
67 | } | |
2aad7cac MZ |
68 | |
69 | # checks that the revisions in "$2" represent a linear range with the | |
70 | # subjects in "$1" | |
71 | test_linear_range () { | |
72 | revlist_merges=$(git rev-list --merges "$2") && | |
73 | test -z "$revlist_merges" && | |
74 | expected=$1 | |
75 | set -- $(git log --reverse --format=%s "$2") | |
76 | test "$expected" = "$*" | |
77 | } | |
78 | ||
79 | reset_rebase () { | |
80 | test_might_fail git rebase --abort && | |
81 | git reset --hard && | |
82 | git clean -f | |
83 | } |