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