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