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