3 test_description
='"git merge" top-level frontend'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 git checkout
-B main two
&&
12 git branch
-f left three
&&
13 git branch
-f right four
16 test_expect_success setup
'
25 git checkout --orphan newroot &&
32 test_expect_success
'merge an octopus into void' '
34 git checkout --orphan test &&
36 test_must_fail git merge left right &&
37 test_must_fail git rev-parse --verify HEAD &&
39 test_must_fail git rev-parse HEAD
42 test_expect_success
'merge an octopus, fast-forward (ff)' '
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
53 test_expect_success
'merge octopus, non-fast-forward (ff)' '
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
64 test_expect_success
'merge octopus, fast-forward (does not ff)' '
66 git merge left right &&
67 # two (main) is not an ancestor of three (left) and four (right)
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
74 test_expect_success
'merge octopus, non-fast-forward' '
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
83 # The same set with FETCH_HEAD
85 test_expect_success
'merge FETCH_HEAD octopus into void' '
87 git checkout --orphan test &&
89 git fetch . left right &&
90 test_must_fail git merge FETCH_HEAD &&
91 test_must_fail git rev-parse --verify HEAD &&
93 test_must_fail git rev-parse HEAD
96 test_expect_success
'merge FETCH_HEAD octopus fast-forward (ff)' '
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
108 test_expect_success
'merge FETCH_HEAD octopus non-fast-forward (ff)' '
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
120 test_expect_success
'merge FETCH_HEAD octopus fast-forward (does not ff)' '
122 git fetch . left right &&
123 git merge FETCH_HEAD &&
124 # two (main) is not an ancestor of three (left) and four (right)
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
131 test_expect_success
'merge FETCH_HEAD octopus non-fast-forward' '
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
142 test_expect_success
'refuse two-project merge by default' '
144 git reset --hard four &&
145 test_must_fail git merge five
148 test_expect_success
'refuse two-project merge by default, quit before --autostash happens' '
150 git reset --hard four &&
151 echo change >>one.t &&
153 test_must_fail git merge --autostash five 2>err &&
154 test_i18ngrep ! "stash" err &&
156 test_cmp expect actual
159 test_expect_success
'two-project merge with --allow-unrelated-histories' '
161 git reset --hard four &&
162 git merge --allow-unrelated-histories five &&
163 git diff --exit-code five
166 test_expect_success
'two-project merge with --allow-unrelated-histories with --autostash' '
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