Merge tag 'v2.23.0-rc0' of git://git.kernel.org/pub/scm/git/git
[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 LF='
16 '
17
18 test_expect_success setup '
19         GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
20         GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" &&
21         export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
22
23         echo >file original &&
24         git add file &&
25         git commit -a -m One &&
26         git tag tag-one &&
27         git tag tag-one-tree HEAD^{tree} &&
28         git branch one &&
29
30         echo two >> file &&
31         git commit -a -m Two &&
32         git tag -a -m "Tag Two" tag-two &&
33         git branch two &&
34
35         echo three >> file &&
36         git commit -a -m Three &&
37         git tag -a -m "Tag Three" tag-three &&
38         git tag -a -m "Tag Three file" tag-three-file HEAD^{tree}:file &&
39         git branch three &&
40
41         echo master >> file &&
42         git commit -a -m Master &&
43         git tag -a -m "Tag Master" tag-master &&
44
45         git checkout three &&
46
47         git clone . cloned &&
48         cd cloned &&
49         git config remote.origin.url ../.git/ &&
50
51         git config remote.config-explicit.url ../.git/ &&
52         git config remote.config-explicit.fetch refs/heads/master:remotes/rem/master &&
53         git config --add remote.config-explicit.fetch refs/heads/one:remotes/rem/one &&
54         git config --add remote.config-explicit.fetch two:remotes/rem/two &&
55         git config --add remote.config-explicit.fetch refs/heads/three:remotes/rem/three &&
56         remotes="config-explicit" &&
57
58         git config remote.config-glob.url ../.git/ &&
59         git config remote.config-glob.fetch refs/heads/*:refs/remotes/rem/* &&
60         remotes="$remotes config-glob" &&
61
62         mkdir -p .git/remotes &&
63         {
64                 echo "URL: ../.git/"
65                 echo "Pull: refs/heads/master:remotes/rem/master"
66                 echo "Pull: refs/heads/one:remotes/rem/one"
67                 echo "Pull: two:remotes/rem/two"
68                 echo "Pull: refs/heads/three:remotes/rem/three"
69         } >.git/remotes/remote-explicit &&
70         remotes="$remotes remote-explicit" &&
71
72         {
73                 echo "URL: ../.git/"
74                 echo "Pull: refs/heads/*:refs/remotes/rem/*"
75         } >.git/remotes/remote-glob &&
76         remotes="$remotes remote-glob" &&
77
78         mkdir -p .git/branches &&
79         echo "../.git" > .git/branches/branches-default &&
80         remotes="$remotes branches-default" &&
81
82         echo "../.git#one" > .git/branches/branches-one &&
83         remotes="$remotes branches-one" &&
84
85         for remote in $remotes ; do
86                 git config branch.br-$remote.remote $remote &&
87                 git config branch.br-$remote-merge.remote $remote &&
88                 git config branch.br-$remote-merge.merge refs/heads/three &&
89                 git config branch.br-$remote-octopus.remote $remote &&
90                 git config branch.br-$remote-octopus.merge refs/heads/one &&
91                 git config --add branch.br-$remote-octopus.merge two
92         done
93 '
94
95 # Merge logic depends on branch properties and Pull: or .fetch lines
96 for remote in $remotes ; do
97     for branch in "" "-merge" "-octopus" ; do
98 cat <<EOF
99 br-$remote$branch
100 br-$remote$branch $remote
101 EOF
102     done
103 done > tests
104
105 # Merge logic does not depend on branch properties,
106 # but does depend on Pull: or fetch lines.
107 # Use two branches completely unrelated from the arguments,
108 # the clone default and one without branch properties
109 for branch in master br-unconfig ; do
110     echo $branch
111     for remote in $remotes ; do
112         echo $branch $remote
113     done
114 done >> tests
115
116 # Merge logic does not depend on branch properties
117 # neither in the Pull: or .fetch config
118 for branch in master br-unconfig ; do
119     cat <<EOF
120 $branch ../.git
121 $branch ../.git one
122 $branch ../.git one two
123 $branch --tags ../.git
124 $branch ../.git tag tag-one tag tag-three
125 $branch ../.git tag tag-one-tree tag tag-three-file
126 $branch ../.git one tag tag-one tag tag-three-file
127 EOF
128 done >> tests
129
130 while read cmd
131 do
132         case "$cmd" in
133         '' | '#'*) continue ;;
134         esac
135         test=$(echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g')
136         pfx=$(printf "%04d" $test_count)
137         expect_f="$TEST_DIRECTORY/t5515/fetch.$test"
138         actual_f="$pfx-fetch.$test"
139         expect_r="$TEST_DIRECTORY/t5515/refs.$test"
140         actual_r="$pfx-refs.$test"
141
142         test_expect_success "$cmd" '
143                 {
144                         echo "# $cmd"
145                         set x $cmd; shift
146                         git symbolic-ref HEAD refs/heads/$1 ; shift
147                         rm -f .git/FETCH_HEAD
148                         git for-each-ref \
149                                 refs/heads refs/remotes/rem refs/tags |
150                         while read val type refname
151                         do
152                                 git update-ref -d "$refname" "$val"
153                         done
154                         git fetch "$@" >/dev/null
155                         cat .git/FETCH_HEAD
156                 } >"$actual_f" &&
157                 git show-ref >"$actual_r" &&
158                 if test -f "$expect_f"
159                 then
160                         test_cmp "$expect_f" "$actual_f" &&
161                         rm -f "$actual_f"
162                 else
163                         # this is to help developing new tests.
164                         cp "$actual_f" "$expect_f"
165                         false
166                 fi &&
167                 if test -f "$expect_r"
168                 then
169                         test_cmp "$expect_r" "$actual_r" &&
170                         rm -f "$actual_r"
171                 else
172                         # this is to help developing new tests.
173                         cp "$actual_r" "$expect_r"
174                         false
175                 fi
176         '
177 done < tests
178
179 test_done