3 test_description
='"git merge" top-level frontend'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
12 git checkout
-B main two
&&
13 git branch
-f left three
&&
14 git branch
-f right four
17 test_expect_success setup
'
26 git checkout --orphan newroot &&
33 test_expect_success
'merge an octopus into void' '
35 git checkout --orphan test &&
37 test_must_fail git merge left right &&
38 test_must_fail git rev-parse --verify HEAD &&
40 test_must_fail git rev-parse HEAD
43 test_expect_success
'merge an octopus, fast-forward (ff)' '
45 git reset --hard one &&
46 git merge left right &&
47 # one is ancestor of three (left) and four (right)
48 test_must_fail git rev-parse --verify HEAD^3 &&
49 git rev-parse HEAD^1 HEAD^2 | sort >actual &&
50 git rev-parse three four | sort >expect &&
51 test_cmp expect actual
54 test_expect_success
'merge octopus, non-fast-forward (ff)' '
56 git reset --hard one &&
57 git merge --no-ff left right &&
58 # one is ancestor of three (left) and four (right)
59 test_must_fail git rev-parse --verify HEAD^4 &&
60 git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
61 git rev-parse one three four | sort >expect &&
62 test_cmp expect actual
65 test_expect_success
'merge octopus, fast-forward (does not ff)' '
67 git merge left right &&
68 # two (main) is not an ancestor of three (left) and four (right)
69 test_must_fail git rev-parse --verify HEAD^4 &&
70 git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
71 git rev-parse two three four | sort >expect &&
72 test_cmp expect actual
75 test_expect_success
'merge octopus, non-fast-forward' '
77 git merge --no-ff left right &&
78 test_must_fail git rev-parse --verify HEAD^4 &&
79 git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
80 git rev-parse two three four | sort >expect &&
81 test_cmp expect actual
84 # The same set with FETCH_HEAD
86 test_expect_success
'merge FETCH_HEAD octopus into void' '
88 git checkout --orphan test &&
90 git fetch . left right &&
91 test_must_fail git merge FETCH_HEAD &&
92 test_must_fail git rev-parse --verify HEAD &&
94 test_must_fail git rev-parse HEAD
97 test_expect_success
'merge FETCH_HEAD octopus fast-forward (ff)' '
99 git reset --hard one &&
100 git fetch . left right &&
101 git merge FETCH_HEAD &&
102 # one is ancestor of three (left) and four (right)
103 test_must_fail git rev-parse --verify HEAD^3 &&
104 git rev-parse HEAD^1 HEAD^2 | sort >actual &&
105 git rev-parse three four | sort >expect &&
106 test_cmp expect actual
109 test_expect_success
'merge FETCH_HEAD octopus non-fast-forward (ff)' '
111 git reset --hard one &&
112 git fetch . left right &&
113 git merge --no-ff FETCH_HEAD &&
114 # one is ancestor of three (left) and four (right)
115 test_must_fail git rev-parse --verify HEAD^4 &&
116 git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
117 git rev-parse one three four | sort >expect &&
118 test_cmp expect actual
121 test_expect_success
'merge FETCH_HEAD octopus fast-forward (does not ff)' '
123 git fetch . left right &&
124 git merge FETCH_HEAD &&
125 # two (main) is not an ancestor of three (left) and four (right)
126 test_must_fail git rev-parse --verify HEAD^4 &&
127 git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
128 git rev-parse two three four | sort >expect &&
129 test_cmp expect actual
132 test_expect_success
'merge FETCH_HEAD octopus non-fast-forward' '
134 git fetch . left right &&
135 git merge --no-ff FETCH_HEAD &&
136 test_must_fail git rev-parse --verify HEAD^4 &&
137 git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
138 git rev-parse two three four | sort >expect &&
139 test_cmp expect actual
143 test_expect_success
'refuse two-project merge by default' '
145 git reset --hard four &&
146 test_must_fail git merge five
149 test_expect_success
'refuse two-project merge by default, quit before --autostash happens' '
151 git reset --hard four &&
152 echo change >>one.t &&
154 test_must_fail git merge --autostash five 2>err &&
155 test_grep ! "stash" err &&
157 test_cmp expect actual
160 test_expect_success
'two-project merge with --allow-unrelated-histories' '
162 git reset --hard four &&
163 git merge --allow-unrelated-histories five &&
164 git diff --exit-code five
167 test_expect_success
'two-project merge with --allow-unrelated-histories with --autostash' '
169 git reset --hard four &&
170 echo change >>one.t &&
171 git diff one.t >expect &&
172 git merge --allow-unrelated-histories --autostash five 2>err &&
173 test_grep "Applied autostash." err &&
174 git diff one.t >actual &&
175 test_cmp expect actual