]>
Commit | Line | Data |
---|---|---|
f8cca019 AE |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright(C) 2008 Stephen Habermann & Andreas Ericsson | |
4 | # | |
5 | test_description='git rebase -p should preserve merges | |
6 | ||
7 | Run "git rebase -p" and check that merges are properly carried along | |
8 | ' | |
9 | . ./test-lib.sh | |
10 | ||
11 | GIT_AUTHOR_EMAIL=bogus_email_address | |
12 | export GIT_AUTHOR_EMAIL | |
13 | ||
03c48293 | 14 | # Clone 1 (trivial merge): |
f8cca019 | 15 | # |
03c48293 JS |
16 | # A1--A2 <-- origin/master |
17 | # \ \ | |
18 | # B1--M <-- topic | |
19 | # \ | |
20 | # B2 <-- origin/topic | |
f8cca019 | 21 | # |
03c48293 JS |
22 | # Clone 2 (conflicting merge): |
23 | # | |
24 | # A1--A2--B3 <-- origin/master | |
25 | # \ \ | |
26 | # B1------M <-- topic | |
27 | # \ | |
28 | # B2 <-- origin/topic | |
29 | # | |
c192f9c8 AW |
30 | # Clone 3 (no-ff merge): |
31 | # | |
32 | # A1--A2--B3 <-- origin/master | |
33 | # \ | |
34 | # B1------M <-- topic | |
35 | # \ / | |
36 | # \--A3 <-- topic2 | |
37 | # \ | |
38 | # B2 <-- origin/topic | |
39 | # | |
12bf8283 AW |
40 | # Clone 4 (merge using second parent as base): |
41 | # | |
42 | # A1--A2--B3 <-- origin/master | |
43 | # \ | |
44 | # B1--A3--M <-- topic | |
45 | # \ / | |
46 | # \--A4 <-- topic2 | |
47 | # \ | |
48 | # B2 <-- origin/topic | |
f8cca019 AE |
49 | |
50 | test_expect_success 'setup for merge-preserving rebase' \ | |
51 | 'echo First > A && | |
52 | git add A && | |
5d59a401 | 53 | git commit -m "Add A1" && |
f8cca019 AE |
54 | git checkout -b topic && |
55 | echo Second > B && | |
56 | git add B && | |
5d59a401 | 57 | git commit -m "Add B1" && |
f8cca019 AE |
58 | git checkout -f master && |
59 | echo Third >> A && | |
5d59a401 | 60 | git commit -a -m "Modify A2" && |
f8cca019 AE |
61 | |
62 | git clone ./. clone1 && | |
fd4ec4f2 | 63 | (cd clone1 && |
f8cca019 | 64 | git checkout -b topic origin/topic && |
fd4ec4f2 JL |
65 | git merge origin/master |
66 | ) && | |
03c48293 | 67 | |
12bf8283 AW |
68 | git clone ./. clone4 && |
69 | ( | |
70 | cd clone4 && | |
71 | git checkout -b topic origin/topic && | |
72 | git merge origin/master | |
73 | ) && | |
74 | ||
03c48293 JS |
75 | echo Fifth > B && |
76 | git add B && | |
77 | git commit -m "Add different B" && | |
f8cca019 | 78 | |
03c48293 | 79 | git clone ./. clone2 && |
18a82692 JN |
80 | ( |
81 | cd clone2 && | |
82 | git checkout -b topic origin/topic && | |
83 | test_must_fail git merge origin/master && | |
84 | echo Resolved >B && | |
85 | git add B && | |
86 | git commit -m "Merge origin/master into topic" | |
fd4ec4f2 | 87 | ) && |
f8cca019 | 88 | |
c192f9c8 AW |
89 | git clone ./. clone3 && |
90 | ( | |
91 | cd clone3 && | |
92 | git checkout -b topic2 origin/topic && | |
93 | echo Sixth > A && | |
94 | git commit -a -m "Modify A3" && | |
95 | git checkout -b topic origin/topic && | |
96 | git merge --no-ff topic2 | |
97 | ) && | |
98 | ||
f8cca019 AE |
99 | git checkout topic && |
100 | echo Fourth >> B && | |
101 | git commit -a -m "Modify B2" | |
102 | ' | |
103 | ||
104 | test_expect_success 'rebase -p fakes interactive rebase' ' | |
03c48293 JS |
105 | ( |
106 | cd clone1 && | |
f8cca019 AE |
107 | git fetch && |
108 | git rebase -p origin/topic && | |
109 | test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) && | |
13931236 | 110 | test 1 = $(git rev-list --all --pretty=oneline | grep "Merge remote-tracking branch " | wc -l) |
03c48293 JS |
111 | ) |
112 | ' | |
113 | ||
f5b49ea6 | 114 | test_expect_success '--continue works after a conflict' ' |
03c48293 JS |
115 | ( |
116 | cd clone2 && | |
117 | git fetch && | |
118 | test_must_fail git rebase -p origin/topic && | |
119 | test 2 = $(git ls-files B | wc -l) && | |
120 | echo Resolved again > B && | |
121 | test_must_fail git rebase --continue && | |
4fb1a19d | 122 | grep "^@@@ " .git/rebase-merge/patch && |
03c48293 JS |
123 | git add B && |
124 | git rebase --continue && | |
125 | test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) && | |
126 | test 1 = $(git rev-list --all --pretty=oneline | grep "Add different" | wc -l) && | |
127 | test 1 = $(git rev-list --all --pretty=oneline | grep "Merge origin" | wc -l) | |
128 | ) | |
f8cca019 AE |
129 | ' |
130 | ||
c192f9c8 AW |
131 | test_expect_success 'rebase -p preserves no-ff merges' ' |
132 | ( | |
133 | cd clone3 && | |
134 | git fetch && | |
135 | git rebase -p origin/topic && | |
136 | test 3 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) && | |
137 | test 1 = $(git rev-list --all --pretty=oneline | grep "Merge branch" | wc -l) | |
138 | ) | |
139 | ' | |
140 | ||
12bf8283 AW |
141 | test_expect_success 'rebase -p works when base inside second parent' ' |
142 | ( | |
143 | cd clone4 && | |
144 | git fetch && | |
145 | git rebase -p HEAD^2 && | |
146 | test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) && | |
147 | test 1 = $(git rev-list --all --pretty=oneline | grep "Modify B" | wc -l) && | |
148 | test 1 = $(git rev-list --all --pretty=oneline | grep "Merge remote-tracking branch " | wc -l) | |
149 | ) | |
150 | ' | |
151 | ||
f8cca019 | 152 | test_done |