gitweb: A bit of code cleanup in git_blame()
[git/gsoc2010-gitweb.git] / t / t3411-rebase-preserve-around-merges.sh
blobaacfaae843395e383d999e570a6bc9942e4c1c0b
1 #!/bin/sh
3 # Copyright (c) 2008 Stephen Haberman
6 test_description='git rebase preserve merges
8 This test runs git rebase with and tries to squash a commit from after a merge
9 to before the merge.
11 . ./test-lib.sh
13 # Copy/paste from t3404-rebase-interactive.sh
14 echo "#!$SHELL_PATH" >fake-editor.sh
15 cat >> fake-editor.sh <<\EOF
16 case "$1" in
17 */COMMIT_EDITMSG)
18 test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
19 test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"
20 exit
22 esac
23 test -z "$EXPECT_COUNT" ||
24 test "$EXPECT_COUNT" = $(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l) ||
25 exit
26 test -z "$FAKE_LINES" && exit
27 grep -v '^#' < "$1" > "$1".tmp
28 rm -f "$1"
29 cat "$1".tmp
30 action=pick
31 for line in $FAKE_LINES; do
32 case $line in
33 squash|edit)
34 action="$line";;
36 echo sed -n "${line}s/^pick/$action/p"
37 sed -n "${line}p" < "$1".tmp
38 sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1"
39 action=pick;;
40 esac
41 done
42 EOF
44 test_set_editor "$(pwd)/fake-editor.sh"
45 chmod a+x fake-editor.sh
47 # set up two branches like this:
49 # A1 - B1 - D1 - E1 - F1
50 # \ /
51 # -- C1 --
53 test_expect_success 'setup' '
54 touch a &&
55 touch b &&
56 git add a &&
57 git commit -m A1 &&
58 git tag A1
59 git add b &&
60 git commit -m B1 &&
61 git tag B1 &&
62 git checkout -b branch &&
63 touch c &&
64 git add c &&
65 git commit -m C1 &&
66 git checkout master &&
67 touch d &&
68 git add d &&
69 git commit -m D1 &&
70 git merge branch &&
71 touch f &&
72 git add f &&
73 git commit -m F1 &&
74 git tag F1
77 # Should result in:
79 # A1 - B1 - D2 - E2
80 # \ /
81 # -- C1 --
83 test_expect_success 'squash F1 into D1' '
84 FAKE_LINES="1 squash 3 2" git rebase -i -p B1 &&
85 test "$(git rev-parse HEAD^2)" = "$(git rev-parse branch)" &&
86 test "$(git rev-parse HEAD~2)" = "$(git rev-parse B1)" &&
87 git tag E2
90 # Start with:
92 # A1 - B1 - D2 - E2
93 # \
94 # G1 ---- L1 ---- M1
95 # \ /
96 # H1 -- J1 -- K1
97 # \ /
98 # -- I1 --
100 # And rebase G1..M1 onto E2
102 test_expect_success 'rebase two levels of merge' '
103 git checkout -b branch2 A1 &&
104 touch g &&
105 git add g &&
106 git commit -m G1 &&
107 git checkout -b branch3 &&
108 touch h
109 git add h &&
110 git commit -m H1 &&
111 git checkout -b branch4 &&
112 touch i &&
113 git add i &&
114 git commit -m I1 &&
115 git tag I1 &&
116 git checkout branch3 &&
117 touch j &&
118 git add j &&
119 git commit -m J1 &&
120 git merge I1 --no-commit &&
121 git commit -m K1 &&
122 git tag K1 &&
123 git checkout branch2 &&
124 touch l &&
125 git add l &&
126 git commit -m L1 &&
127 git merge K1 --no-commit &&
128 git commit -m M1 &&
129 GIT_EDITOR=: git rebase -i -p E2 &&
130 test "$(git rev-parse HEAD~3)" = "$(git rev-parse E2)" &&
131 test "$(git rev-parse HEAD~2)" = "$(git rev-parse HEAD^2^2~2)" &&
132 test "$(git rev-parse HEAD^2^1^1)" = "$(git rev-parse HEAD^2^2^1)"
135 test_done