]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6433-merge-toplevel.sh
The third batch
[thirdparty/git.git] / t / t6433-merge-toplevel.sh
CommitLineData
9e62316d
JH
1#!/bin/sh
2
3test_description='"git merge" top-level frontend'
4
5902f5f4 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
716a6b2c 8TEST_PASSES_SANITIZE_LEAK=true
9e62316d
JH
9. ./test-lib.sh
10
11t3033_reset () {
5902f5f4 12 git checkout -B main two &&
9e62316d
JH
13 git branch -f left three &&
14 git branch -f right four
15}
16
17test_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 &&
de224962 26 git checkout --orphan newroot &&
e379fdf3 27 test_commit five &&
5902f5f4 28 git checkout main
9e62316d
JH
29'
30
31# Local branches
32
33test_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
41'
42
43test_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
52'
53
54test_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
63'
64
65test_expect_success 'merge octopus, fast-forward (does not ff)' '
66 t3033_reset &&
67 git merge left right &&
5902f5f4 68 # two (main) is not an ancestor of three (left) and four (right)
9e62316d
JH
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
73'
74
75test_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
82'
83
84# The same set with FETCH_HEAD
85
74e8bc59 86test_expect_success 'merge FETCH_HEAD octopus into void' '
9e62316d
JH
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
95'
96
74e8bc59 97test_expect_success 'merge FETCH_HEAD octopus fast-forward (ff)' '
9e62316d
JH
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
107'
108
74e8bc59 109test_expect_success 'merge FETCH_HEAD octopus non-fast-forward (ff)' '
9e62316d
JH
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
119'
120
74e8bc59 121test_expect_success 'merge FETCH_HEAD octopus fast-forward (does not ff)' '
9e62316d
JH
122 t3033_reset &&
123 git fetch . left right &&
124 git merge FETCH_HEAD &&
5902f5f4 125 # two (main) is not an ancestor of three (left) and four (right)
9e62316d
JH
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
130'
131
74e8bc59 132test_expect_success 'merge FETCH_HEAD octopus non-fast-forward' '
9e62316d
JH
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
140'
141
e379fdf3
JH
142# two-project merge
143test_expect_success 'refuse two-project merge by default' '
144 t3033_reset &&
145 git reset --hard four &&
146 test_must_fail git merge five
147'
148
a03b5553
DL
149test_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 &&
6789275d 155 test_grep ! "stash" err &&
a03b5553
DL
156 git diff >actual &&
157 test_cmp expect actual
158'
159
e379fdf3
JH
160test_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
165'
166
a03b5553
DL
167test_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 &&
6789275d 173 test_grep "Applied autostash." err &&
a03b5553
DL
174 git diff one.t >actual &&
175 test_cmp expect actual
176'
177
9e62316d 178test_done