]>
Commit | Line | Data |
---|---|---|
9e62316d JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='"git merge" top-level frontend' | |
4 | ||
5902f5f4 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
9e62316d JH |
8 | . ./test-lib.sh |
9 | ||
10 | t3033_reset () { | |
5902f5f4 | 11 | git checkout -B main two && |
9e62316d JH |
12 | git branch -f left three && |
13 | git branch -f right four | |
14 | } | |
15 | ||
16 | test_expect_success setup ' | |
17 | test_commit one && | |
18 | git branch left && | |
19 | git branch right && | |
20 | test_commit two && | |
21 | git checkout left && | |
22 | test_commit three && | |
23 | git checkout right && | |
24 | test_commit four && | |
de224962 | 25 | git checkout --orphan newroot && |
e379fdf3 | 26 | test_commit five && |
5902f5f4 | 27 | git checkout main |
9e62316d JH |
28 | ' |
29 | ||
30 | # Local branches | |
31 | ||
32 | test_expect_success 'merge an octopus into void' ' | |
33 | t3033_reset && | |
34 | git checkout --orphan test && | |
35 | git rm -fr . && | |
36 | test_must_fail git merge left right && | |
37 | test_must_fail git rev-parse --verify HEAD && | |
38 | git diff --quiet && | |
39 | test_must_fail git rev-parse HEAD | |
40 | ' | |
41 | ||
42 | test_expect_success 'merge an octopus, fast-forward (ff)' ' | |
43 | t3033_reset && | |
44 | git reset --hard one && | |
45 | git merge left right && | |
46 | # one is ancestor of three (left) and four (right) | |
47 | test_must_fail git rev-parse --verify HEAD^3 && | |
48 | git rev-parse HEAD^1 HEAD^2 | sort >actual && | |
49 | git rev-parse three four | sort >expect && | |
50 | test_cmp expect actual | |
51 | ' | |
52 | ||
53 | test_expect_success 'merge octopus, non-fast-forward (ff)' ' | |
54 | t3033_reset && | |
55 | git reset --hard one && | |
56 | git merge --no-ff left right && | |
57 | # one is ancestor of three (left) and four (right) | |
58 | test_must_fail git rev-parse --verify HEAD^4 && | |
59 | git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual && | |
60 | git rev-parse one three four | sort >expect && | |
61 | test_cmp expect actual | |
62 | ' | |
63 | ||
64 | test_expect_success 'merge octopus, fast-forward (does not ff)' ' | |
65 | t3033_reset && | |
66 | git merge left right && | |
5902f5f4 | 67 | # two (main) is not an ancestor of three (left) and four (right) |
9e62316d JH |
68 | test_must_fail git rev-parse --verify HEAD^4 && |
69 | git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual && | |
70 | git rev-parse two three four | sort >expect && | |
71 | test_cmp expect actual | |
72 | ' | |
73 | ||
74 | test_expect_success 'merge octopus, non-fast-forward' ' | |
75 | t3033_reset && | |
76 | git merge --no-ff left right && | |
77 | test_must_fail git rev-parse --verify HEAD^4 && | |
78 | git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual && | |
79 | git rev-parse two three four | sort >expect && | |
80 | test_cmp expect actual | |
81 | ' | |
82 | ||
83 | # The same set with FETCH_HEAD | |
84 | ||
74e8bc59 | 85 | test_expect_success 'merge FETCH_HEAD octopus into void' ' |
9e62316d JH |
86 | t3033_reset && |
87 | git checkout --orphan test && | |
88 | git rm -fr . && | |
89 | git fetch . left right && | |
90 | test_must_fail git merge FETCH_HEAD && | |
91 | test_must_fail git rev-parse --verify HEAD && | |
92 | git diff --quiet && | |
93 | test_must_fail git rev-parse HEAD | |
94 | ' | |
95 | ||
74e8bc59 | 96 | test_expect_success 'merge FETCH_HEAD octopus fast-forward (ff)' ' |
9e62316d JH |
97 | t3033_reset && |
98 | git reset --hard one && | |
99 | git fetch . left right && | |
100 | git merge FETCH_HEAD && | |
101 | # one is ancestor of three (left) and four (right) | |
102 | test_must_fail git rev-parse --verify HEAD^3 && | |
103 | git rev-parse HEAD^1 HEAD^2 | sort >actual && | |
104 | git rev-parse three four | sort >expect && | |
105 | test_cmp expect actual | |
106 | ' | |
107 | ||
74e8bc59 | 108 | test_expect_success 'merge FETCH_HEAD octopus non-fast-forward (ff)' ' |
9e62316d JH |
109 | t3033_reset && |
110 | git reset --hard one && | |
111 | git fetch . left right && | |
112 | git merge --no-ff FETCH_HEAD && | |
113 | # one is ancestor of three (left) and four (right) | |
114 | test_must_fail git rev-parse --verify HEAD^4 && | |
115 | git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual && | |
116 | git rev-parse one three four | sort >expect && | |
117 | test_cmp expect actual | |
118 | ' | |
119 | ||
74e8bc59 | 120 | test_expect_success 'merge FETCH_HEAD octopus fast-forward (does not ff)' ' |
9e62316d JH |
121 | t3033_reset && |
122 | git fetch . left right && | |
123 | git merge FETCH_HEAD && | |
5902f5f4 | 124 | # two (main) is not an ancestor of three (left) and four (right) |
9e62316d JH |
125 | test_must_fail git rev-parse --verify HEAD^4 && |
126 | git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual && | |
127 | git rev-parse two three four | sort >expect && | |
128 | test_cmp expect actual | |
129 | ' | |
130 | ||
74e8bc59 | 131 | test_expect_success 'merge FETCH_HEAD octopus non-fast-forward' ' |
9e62316d JH |
132 | t3033_reset && |
133 | git fetch . left right && | |
134 | git merge --no-ff FETCH_HEAD && | |
135 | test_must_fail git rev-parse --verify HEAD^4 && | |
136 | git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual && | |
137 | git rev-parse two three four | sort >expect && | |
138 | test_cmp expect actual | |
139 | ' | |
140 | ||
e379fdf3 JH |
141 | # two-project merge |
142 | test_expect_success 'refuse two-project merge by default' ' | |
143 | t3033_reset && | |
144 | git reset --hard four && | |
145 | test_must_fail git merge five | |
146 | ' | |
147 | ||
a03b5553 DL |
148 | test_expect_success 'refuse two-project merge by default, quit before --autostash happens' ' |
149 | t3033_reset && | |
150 | git reset --hard four && | |
151 | echo change >>one.t && | |
152 | git diff >expect && | |
153 | test_must_fail git merge --autostash five 2>err && | |
154 | test_i18ngrep ! "stash" err && | |
155 | git diff >actual && | |
156 | test_cmp expect actual | |
157 | ' | |
158 | ||
e379fdf3 JH |
159 | test_expect_success 'two-project merge with --allow-unrelated-histories' ' |
160 | t3033_reset && | |
161 | git reset --hard four && | |
162 | git merge --allow-unrelated-histories five && | |
163 | git diff --exit-code five | |
164 | ' | |
165 | ||
a03b5553 DL |
166 | test_expect_success 'two-project merge with --allow-unrelated-histories with --autostash' ' |
167 | t3033_reset && | |
168 | git reset --hard four && | |
169 | echo change >>one.t && | |
170 | git diff one.t >expect && | |
171 | git merge --allow-unrelated-histories --autostash five 2>err && | |
172 | test_i18ngrep "Applied autostash." err && | |
173 | git diff one.t >actual && | |
174 | test_cmp expect actual | |
175 | ' | |
176 | ||
9e62316d | 177 | test_done |