]>
Commit | Line | Data |
---|---|---|
c74c7203 | 1 | # Helper functions used by interactive rebase tests. |
29a03348 | 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 | 16 | # "<cmd> <lineno>" -- add a line with the specified command |
7afb0d67 SG |
17 | # ("pick", "squash", "fixup", "edit", "reword" or "drop") and the |
18 | # SHA1 taken from the specified line. | |
05c95dbe | 19 | # |
296fa993 AP |
20 | # "exec_cmd_with_args" -- add an "exec cmd with args" line. |
21 | # | |
05c95dbe MH |
22 | # "#" -- Add a comment line. |
23 | # | |
24 | # ">" -- Add a blank line. | |
03af0870 | 25 | |
29a03348 | 26 | set_fake_editor () { |
a4952815 AP |
27 | write_script fake-editor.sh <<-\EOF |
28 | case "$1" in | |
29 | */COMMIT_EDITMSG) | |
30 | test -z "$EXPECT_HEADER_COUNT" || | |
31 | test "$EXPECT_HEADER_COUNT" = "$(sed -n '1s/^# This is a combination of \(.*\) commits\./\1/p' < "$1")" || | |
32 | exit | |
33 | test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1" | |
34 | test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1" | |
959c0d06 | 35 | exit |
a4952815 | 36 | ;; |
29a03348 | 37 | esac |
a4952815 AP |
38 | test -z "$EXPECT_COUNT" || |
39 | test "$EXPECT_COUNT" = $(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l) || | |
40 | exit | |
41 | test -z "$FAKE_LINES" && exit | |
42 | grep -v '^#' < "$1" > "$1".tmp | |
43 | rm -f "$1" | |
44 | echo 'rebase -i script before editing:' | |
45 | cat "$1".tmp | |
5dcdd740 | 46 | action=\& |
a4952815 AP |
47 | for line in $FAKE_LINES; do |
48 | case $line in | |
5dcdd740 | 49 | pick|p|squash|s|fixup|f|edit|e|reword|r|drop|d|label|l|reset|r|merge|m) |
a4952815 | 50 | action="$line";; |
b3635c15 | 51 | exec_*|x_*|break|b) |
a4952815 AP |
52 | echo "$line" | sed 's/_/ /g' >> "$1";; |
53 | "#") | |
54 | echo '# comment' >> "$1";; | |
55 | ">") | |
56 | echo >> "$1";; | |
804098bb GR |
57 | bad) |
58 | action="badcmd";; | |
59 | fakesha) | |
5dcdd740 | 60 | test \& != "$action" || action=pick |
804098bb GR |
61 | echo "$action XXXXXXX False commit" >> "$1" |
62 | action=pick;; | |
a4952815 | 63 | *) |
5dcdd740 JS |
64 | sed -n "${line}s/^[a-z][a-z]*/$action/p" < "$1".tmp >> "$1" |
65 | action=\&;; | |
a4952815 AP |
66 | esac |
67 | done | |
68 | echo 'rebase -i script after editing:' | |
69 | cat "$1" | |
70 | EOF | |
29a03348 JS |
71 | |
72 | test_set_editor "$(pwd)/fake-editor.sh" | |
29a03348 | 73 | } |
2aad7cac | 74 | |
22c5b136 AP |
75 | # After set_cat_todo_editor, rebase -i will write the todo list (ignoring |
76 | # blank lines and comments) to stdout, and exit failure (so you should run | |
77 | # it with test_must_fail). This can be used to verify the expected user | |
78 | # experience, for todo list changes that do not affect the outcome of | |
79 | # rebase; or as an extra check in addition to checking the outcome. | |
80 | ||
81 | set_cat_todo_editor () { | |
82 | write_script fake-editor.sh <<-\EOF | |
83 | grep "^[^#]" "$1" | |
84 | exit 1 | |
85 | EOF | |
86 | test_set_editor "$(pwd)/fake-editor.sh" | |
87 | } | |
88 | ||
2aad7cac MZ |
89 | # checks that the revisions in "$2" represent a linear range with the |
90 | # subjects in "$1" | |
91 | test_linear_range () { | |
92 | revlist_merges=$(git rev-list --merges "$2") && | |
93 | test -z "$revlist_merges" && | |
94 | expected=$1 | |
95 | set -- $(git log --reverse --format=%s "$2") | |
96 | test "$expected" = "$*" | |
97 | } | |
98 | ||
99 | reset_rebase () { | |
100 | test_might_fail git rebase --abort && | |
101 | git reset --hard && | |
102 | git clean -f | |
103 | } | |
5b5e1c7c MZ |
104 | |
105 | cherry_pick () { | |
106 | git cherry-pick -n "$2" && | |
107 | git commit -m "$1" && | |
108 | git tag "$1" | |
109 | } | |
110 | ||
111 | revert () { | |
112 | git revert -n "$2" && | |
113 | git commit -m "$1" && | |
114 | git tag "$1" | |
115 | } | |
116 | ||
117 | make_empty () { | |
118 | git commit --allow-empty -m "$1" && | |
119 | git tag "$1" | |
120 | } | |
6a619ca0 PW |
121 | |
122 | # Call this (inside test_expect_success) at the end of a test file to | |
123 | # check that no tests have changed editor related environment | |
124 | # variables or config settings | |
125 | test_editor_unchanged () { | |
126 | # We're only interested in exported variables hence 'sh -c' | |
127 | sh -c 'cat >actual <<-EOF | |
128 | EDITOR=$EDITOR | |
129 | FAKE_COMMIT_AMEND=$FAKE_COMMIT_AMEND | |
130 | FAKE_COMMIT_MESSAGE=$FAKE_COMMIT_MESSAGE | |
131 | FAKE_LINES=$FAKE_LINES | |
132 | GIT_EDITOR=$GIT_EDITOR | |
133 | GIT_SEQUENCE_EDITOR=$GIT_SEQUENCE_EDITOR | |
134 | core.editor=$(git config core.editor) | |
135 | sequence.editor=$(git config sequence.editor) | |
136 | EOF' | |
137 | cat >expect <<-\EOF | |
138 | EDITOR=: | |
139 | FAKE_COMMIT_AMEND= | |
140 | FAKE_COMMIT_MESSAGE= | |
141 | FAKE_LINES= | |
142 | GIT_EDITOR= | |
143 | GIT_SEQUENCE_EDITOR= | |
144 | core.editor= | |
145 | sequence.editor= | |
146 | EOF | |
147 | test_cmp expect actual | |
148 | } |