]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5515-fetch-merge-logic.sh
The third batch
[thirdparty/git.git] / t / t5515-fetch-merge-logic.sh
CommitLineData
ac3ec0d5
SB
1#!/bin/sh
2#
3# Copyright (c) 2007 Santi Béjar, based on t4013 by Junio C Hamano
4#
5#
6
7test_description='Merge logic in fetch'
8
d790ee17
JT
9# NEEDSWORK: If the overspecification of the expected result is reduced, we
10# might be able to run this test in all protocol versions.
8a1b0978
JN
11GIT_TEST_PROTOCOL_VERSION=0
12export GIT_TEST_PROTOCOL_VERSION
d790ee17 13
f74e3f79 14GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
62e7daa0
JS
15export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
16
7a98d9ab 17TEST_PASSES_SANITIZE_LEAK=true
ac3ec0d5
SB
18. ./test-lib.sh
19
f7ae8e69 20build_script () {
21 script="$1" &&
62e7daa0 22 for i in one three_file main topic_2 one_tree three two two2 three2
f7ae8e69 23 do
24 echo "s/$(test_oid --hash=sha1 "$i")/$(test_oid "$i")/g" >>"$script"
25 done
26}
27
28convert_expected () {
29 file="$1" &&
30 script="$2" &&
31 sed -f "$script" "$file" >"$file.tmp" &&
32 mv "$file.tmp" "$file"
33}
34
ac3ec0d5
SB
35test_expect_success setup '
36 GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
37 GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" &&
38 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
39
f7ae8e69 40 test_oid_cache <<-EOF &&
41 one sha1:8e32a6d901327a23ef831511badce7bf3bf46689
42 one sha256:8739546433ab1ac72ee93088dce611210effee072b2b586ceac6dde43ebec9ce
43
44 three_file sha1:0e3b14047d3ee365f4f2a1b673db059c3972589c
45 three_file sha256:bc4447d50c07497a8bfe6eef817f2364ecca9d471452e43b52756cc1a908bd32
46
62e7daa0
JS
47 main sha1:ecf3b3627b498bdcb735cc4343bf165f76964e9a
48 main sha256:fff666109892bb4b1c80cd1649d2d8762a0663db8b5d46c8be98360b64fbba5f
f7ae8e69 49
50 one_tree sha1:22feea448b023a2d864ef94b013735af34d238ba
51 one_tree sha256:6e4743f4ef2356b881dda5e91f5c7cdffe870faf350bf7b312f80a20935f5d83
52
53 three sha1:c61a82b60967180544e3c19f819ddbd0c9f89899
54 three sha256:0cc6d1eda617ded715170786e31ba4e2d0185404ec5a3508dd0d73b324860c6a
55
56 two sha1:525b7fb068d59950d185a8779dc957c77eed73ba
57 two sha256:3b21de3440cd38c2a9e9b464adb923f7054949ed4c918e1a0ac4c95cd52774db
58
62e7daa0
JS
59 topic_2 sha1:b4ab76b1a01ea602209932134a44f1e6bd610832
60 topic_2 sha256:380ebae0113f877ce46fcdf39d5bc33e4dc0928db5c5a4d5fdc78381c4d55ae3
f7ae8e69 61
62 two2 sha1:6134ee8f857693b96ff1cc98d3e2fd62b199e5a8
63 two2 sha256:87a2d3ee29c83a3dc7afd41c0606b11f67603120b910a7be7840accdc18344d4
64
65 three2 sha1:0567da4d5edd2ff4bb292a465ba9e64dcad9536b
66 three2 sha256:cceb3e8eca364fa9a0a39a1efbebecacc664af86cbbd8070571f5faeb5f0e8c3
67 EOF
68
ac3ec0d5
SB
69 echo >file original &&
70 git add file &&
71 git commit -a -m One &&
72 git tag tag-one &&
73 git tag tag-one-tree HEAD^{tree} &&
74 git branch one &&
75
76 echo two >> file &&
77 git commit -a -m Two &&
78 git tag -a -m "Tag Two" tag-two &&
79 git branch two &&
80
81 echo three >> file &&
82 git commit -a -m Three &&
83 git tag -a -m "Tag Three" tag-three &&
84 git tag -a -m "Tag Three file" tag-three-file HEAD^{tree}:file &&
85 git branch three &&
86
62e7daa0
JS
87 echo main >> file &&
88 git commit -a -m Main &&
89 git tag -a -m "Tag Main" tag-main &&
ac3ec0d5
SB
90
91 git checkout three &&
92
93 git clone . cloned &&
94 cd cloned &&
95 git config remote.origin.url ../.git/ &&
96
97 git config remote.config-explicit.url ../.git/ &&
62e7daa0 98 git config remote.config-explicit.fetch refs/heads/main:remotes/rem/main &&
ac3ec0d5
SB
99 git config --add remote.config-explicit.fetch refs/heads/one:remotes/rem/one &&
100 git config --add remote.config-explicit.fetch two:remotes/rem/two &&
101 git config --add remote.config-explicit.fetch refs/heads/three:remotes/rem/three &&
102 remotes="config-explicit" &&
103
104 git config remote.config-glob.url ../.git/ &&
105 git config remote.config-glob.fetch refs/heads/*:refs/remotes/rem/* &&
106 remotes="$remotes config-glob" &&
107
108 mkdir -p .git/remotes &&
020b813f
ES
109 cat >.git/remotes/remote-explicit <<-\EOF &&
110 URL: ../.git/
111 Pull: refs/heads/main:remotes/rem/main
112 Pull: refs/heads/one:remotes/rem/one
113 Pull: two:remotes/rem/two
114 Pull: refs/heads/three:remotes/rem/three
115 EOF
ac3ec0d5
SB
116 remotes="$remotes remote-explicit" &&
117
020b813f
ES
118 cat >.git/remotes/remote-glob <<-\EOF &&
119 URL: ../.git/
120 Pull: refs/heads/*:refs/remotes/rem/*
121 EOF
ac3ec0d5
SB
122 remotes="$remotes remote-glob" &&
123
124 mkdir -p .git/branches &&
125 echo "../.git" > .git/branches/branches-default &&
126 remotes="$remotes branches-default" &&
127
128 echo "../.git#one" > .git/branches/branches-one &&
129 remotes="$remotes branches-one" &&
130
131 for remote in $remotes ; do
132 git config branch.br-$remote.remote $remote &&
133 git config branch.br-$remote-merge.remote $remote &&
134 git config branch.br-$remote-merge.merge refs/heads/three &&
135 git config branch.br-$remote-octopus.remote $remote &&
136 git config branch.br-$remote-octopus.merge refs/heads/one &&
d0fd9931 137 git config --add branch.br-$remote-octopus.merge two || return 1
f7ae8e69 138 done &&
139 build_script sed_script
ac3ec0d5
SB
140'
141
142# Merge logic depends on branch properties and Pull: or .fetch lines
143for remote in $remotes ; do
144 for branch in "" "-merge" "-octopus" ; do
145cat <<EOF
146br-$remote$branch
147br-$remote$branch $remote
148EOF
149 done
150done > tests
151
152# Merge logic does not depend on branch properties,
153# but does depend on Pull: or fetch lines.
154# Use two branches completely unrelated from the arguments,
155# the clone default and one without branch properties
62e7daa0 156for branch in main br-unconfig ; do
ac3ec0d5
SB
157 echo $branch
158 for remote in $remotes ; do
159 echo $branch $remote
160 done
161done >> tests
162
163# Merge logic does not depend on branch properties
164# neither in the Pull: or .fetch config
62e7daa0 165for branch in main br-unconfig ; do
ac3ec0d5 166 cat <<EOF
e3d842cf 167$branch ../.git
ac3ec0d5
SB
168$branch ../.git one
169$branch ../.git one two
170$branch --tags ../.git
171$branch ../.git tag tag-one tag tag-three
172$branch ../.git tag tag-one-tree tag tag-three-file
173$branch ../.git one tag tag-one tag tag-three-file
174EOF
175done >> tests
176
177while read cmd
178do
179 case "$cmd" in
180 '' | '#'*) continue ;;
181 esac
28666e55
EP
182 test=$(echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g')
183 pfx=$(printf "%04d" $test_count)
bfdbee98 184 expect_f="$TEST_DIRECTORY/t5515/fetch.$test"
a466637c 185 actual_f="$pfx-fetch.$test"
bfdbee98 186 expect_r="$TEST_DIRECTORY/t5515/refs.$test"
a466637c 187 actual_r="$pfx-refs.$test"
ac3ec0d5
SB
188
189 test_expect_success "$cmd" '
f7ae8e69 190 cp "$expect_f" expect_f &&
191 convert_expected expect_f sed_script &&
192 cp "$expect_r" expect_r &&
193 convert_expected expect_r sed_script &&
ac3ec0d5 194 {
7abcbcb7
ES
195 echo "# $cmd" &&
196 set x $cmd && shift &&
197 git symbolic-ref HEAD refs/heads/$1 && shift &&
198 rm -f .git/FETCH_HEAD &&
d0d12b47
JH
199 git for-each-ref \
200 refs/heads refs/remotes/rem refs/tags |
201 while read val type refname
202 do
d0fd9931 203 git update-ref -d "$refname" "$val" || return 1
7abcbcb7
ES
204 done &&
205 git fetch "$@" >/dev/null &&
ac3ec0d5 206 cat .git/FETCH_HEAD
a466637c
JH
207 } >"$actual_f" &&
208 git show-ref >"$actual_r" &&
f7ae8e69 209 if test -f "expect_f"
ac3ec0d5 210 then
f7ae8e69 211 test_cmp "expect_f" "$actual_f" &&
a466637c 212 rm -f "$actual_f"
ac3ec0d5
SB
213 else
214 # this is to help developing new tests.
a466637c
JH
215 cp "$actual_f" "$expect_f"
216 false
217 fi &&
f7ae8e69 218 if test -f "expect_r"
a466637c 219 then
f7ae8e69 220 test_cmp "expect_r" "$actual_r" &&
a466637c
JH
221 rm -f "$actual_r"
222 else
223 # this is to help developing new tests.
224 cp "$actual_r" "$expect_r"
ac3ec0d5
SB
225 false
226 fi
227 '
228done < tests
229
230test_done