]> git.ipfire.org Git - thirdparty/git.git/blame - t/lib-rebase.sh
git rebase -i: warn about removed commits
[thirdparty/git.git] / t / lib-rebase.sh
CommitLineData
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
c9266d58 17# ("squash", "fixup", "edit", "reword" or "drop") and the SHA1 taken
05c95dbe
MH
18# from the specified line.
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 26set_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
46 action=pick
47 for line in $FAKE_LINES; do
48 case $line in
c9266d58 49 squash|fixup|edit|reword|drop)
a4952815
AP
50 action="$line";;
51 exec*)
52 echo "$line" | sed 's/_/ /g' >> "$1";;
53 "#")
54 echo '# comment' >> "$1";;
55 ">")
56 echo >> "$1";;
57 *)
58 sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1"
59 action=pick;;
60 esac
61 done
62 echo 'rebase -i script after editing:'
63 cat "$1"
64 EOF
29a03348
JS
65
66 test_set_editor "$(pwd)/fake-editor.sh"
29a03348 67}
2aad7cac 68
22c5b136
AP
69# After set_cat_todo_editor, rebase -i will write the todo list (ignoring
70# blank lines and comments) to stdout, and exit failure (so you should run
71# it with test_must_fail). This can be used to verify the expected user
72# experience, for todo list changes that do not affect the outcome of
73# rebase; or as an extra check in addition to checking the outcome.
74
75set_cat_todo_editor () {
76 write_script fake-editor.sh <<-\EOF
77 grep "^[^#]" "$1"
78 exit 1
79 EOF
80 test_set_editor "$(pwd)/fake-editor.sh"
81}
82
2aad7cac
MZ
83# checks that the revisions in "$2" represent a linear range with the
84# subjects in "$1"
85test_linear_range () {
86 revlist_merges=$(git rev-list --merges "$2") &&
87 test -z "$revlist_merges" &&
88 expected=$1
89 set -- $(git log --reverse --format=%s "$2")
90 test "$expected" = "$*"
91}
92
93reset_rebase () {
94 test_might_fail git rebase --abort &&
95 git reset --hard &&
96 git clean -f
97}
5b5e1c7c
MZ
98
99cherry_pick () {
100 git cherry-pick -n "$2" &&
101 git commit -m "$1" &&
102 git tag "$1"
103}
104
105revert () {
106 git revert -n "$2" &&
107 git commit -m "$1" &&
108 git tag "$1"
109}
110
111make_empty () {
112 git commit --allow-empty -m "$1" &&
113 git tag "$1"
114}