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