Sync with 'maint'
[alt-git.git] / t / t6433-merge-toplevel.sh
blobed7866d3e955a3d093b6428b750f4d8d7ec1ae63
1 #!/bin/sh
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
9 . ./test-lib.sh
11 t3033_reset () {
12 git checkout -B main two &&
13 git branch -f left three &&
14 git branch -f right four
17 test_expect_success setup '
18 test_commit one &&
19 git branch left &&
20 git branch right &&
21 test_commit two &&
22 git checkout left &&
23 test_commit three &&
24 git checkout right &&
25 test_commit four &&
26 git checkout --orphan newroot &&
27 test_commit five &&
28 git checkout main
31 # Local branches
33 test_expect_success 'merge an octopus into void' '
34 t3033_reset &&
35 git checkout --orphan test &&
36 git rm -fr . &&
37 test_must_fail git merge left right &&
38 test_must_fail git rev-parse --verify HEAD &&
39 git diff --quiet &&
40 test_must_fail git rev-parse HEAD
43 test_expect_success 'merge an octopus, fast-forward (ff)' '
44 t3033_reset &&
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)' '
55 t3033_reset &&
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)' '
66 t3033_reset &&
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' '
76 t3033_reset &&
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' '
87 t3033_reset &&
88 git checkout --orphan test &&
89 git rm -fr . &&
90 git fetch . left right &&
91 test_must_fail git merge FETCH_HEAD &&
92 test_must_fail git rev-parse --verify HEAD &&
93 git diff --quiet &&
94 test_must_fail git rev-parse HEAD
97 test_expect_success 'merge FETCH_HEAD octopus fast-forward (ff)' '
98 t3033_reset &&
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)' '
110 t3033_reset &&
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)' '
122 t3033_reset &&
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' '
133 t3033_reset &&
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
142 # two-project merge
143 test_expect_success 'refuse two-project merge by default' '
144 t3033_reset &&
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' '
150 t3033_reset &&
151 git reset --hard four &&
152 echo change >>one.t &&
153 git diff >expect &&
154 test_must_fail git merge --autostash five 2>err &&
155 test_grep ! "stash" err &&
156 git diff >actual &&
157 test_cmp expect actual
160 test_expect_success 'two-project merge with --allow-unrelated-histories' '
161 t3033_reset &&
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' '
168 t3033_reset &&
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
178 test_done