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