blob: dbb927dec8ea9f40e8e106f416c276f1b6a07868 [file] [log] [blame]
Santi Béjarac3ec0d2007-03-05 09:09:39 +01001#!/bin/sh
2#
3# Copyright (c) 2007 Santi Béjar, based on t4013 by Junio C Hamano
4#
5#
6
7test_description='Merge logic in fetch'
8
9. ./test-lib.sh
10
11LF='
12'
13
14test_expect_success setup '
15 GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
16 GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" &&
17 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
18
19 echo >file original &&
20 git add file &&
21 git commit -a -m One &&
22 git tag tag-one &&
23 git tag tag-one-tree HEAD^{tree} &&
24 git branch one &&
25
26 echo two >> file &&
27 git commit -a -m Two &&
28 git tag -a -m "Tag Two" tag-two &&
29 git branch two &&
30
31 echo three >> file &&
32 git commit -a -m Three &&
33 git tag -a -m "Tag Three" tag-three &&
34 git tag -a -m "Tag Three file" tag-three-file HEAD^{tree}:file &&
35 git branch three &&
36
37 echo master >> file &&
38 git commit -a -m Master &&
39 git tag -a -m "Tag Master" tag-master &&
40
41 git checkout three &&
42
43 git clone . cloned &&
44 cd cloned &&
45 git config remote.origin.url ../.git/ &&
46
47 git config remote.config-explicit.url ../.git/ &&
48 git config remote.config-explicit.fetch refs/heads/master:remotes/rem/master &&
49 git config --add remote.config-explicit.fetch refs/heads/one:remotes/rem/one &&
50 git config --add remote.config-explicit.fetch two:remotes/rem/two &&
51 git config --add remote.config-explicit.fetch refs/heads/three:remotes/rem/three &&
52 remotes="config-explicit" &&
53
54 git config remote.config-glob.url ../.git/ &&
55 git config remote.config-glob.fetch refs/heads/*:refs/remotes/rem/* &&
56 remotes="$remotes config-glob" &&
57
58 mkdir -p .git/remotes &&
59 {
60 echo "URL: ../.git/"
61 echo "Pull: refs/heads/master:remotes/rem/master"
62 echo "Pull: refs/heads/one:remotes/rem/one"
63 echo "Pull: two:remotes/rem/two"
64 echo "Pull: refs/heads/three:remotes/rem/three"
65 } >.git/remotes/remote-explicit &&
66 remotes="$remotes remote-explicit" &&
67
68 {
69 echo "URL: ../.git/"
70 echo "Pull: refs/heads/*:refs/remotes/rem/*"
71 } >.git/remotes/remote-glob &&
72 remotes="$remotes remote-glob" &&
73
74 mkdir -p .git/branches &&
75 echo "../.git" > .git/branches/branches-default &&
76 remotes="$remotes branches-default" &&
77
78 echo "../.git#one" > .git/branches/branches-one &&
79 remotes="$remotes branches-one" &&
80
81 for remote in $remotes ; do
82 git config branch.br-$remote.remote $remote &&
83 git config branch.br-$remote-merge.remote $remote &&
84 git config branch.br-$remote-merge.merge refs/heads/three &&
85 git config branch.br-$remote-octopus.remote $remote &&
86 git config branch.br-$remote-octopus.merge refs/heads/one &&
Shawn O. Pearced8b3a2b2007-09-18 04:54:51 -040087 git config --add branch.br-$remote-octopus.merge two
Santi Béjarac3ec0d2007-03-05 09:09:39 +010088 done
89'
90
91# Merge logic depends on branch properties and Pull: or .fetch lines
92for remote in $remotes ; do
93 for branch in "" "-merge" "-octopus" ; do
94cat <<EOF
95br-$remote$branch
96br-$remote$branch $remote
97EOF
98 done
99done > tests
100
101# Merge logic does not depend on branch properties,
102# but does depend on Pull: or fetch lines.
103# Use two branches completely unrelated from the arguments,
104# the clone default and one without branch properties
105for branch in master br-unconfig ; do
106 echo $branch
107 for remote in $remotes ; do
108 echo $branch $remote
109 done
110done >> tests
111
112# Merge logic does not depend on branch properties
113# neither in the Pull: or .fetch config
114for branch in master br-unconfig ; do
115 cat <<EOF
Santi B,Ai(Bjare3d842c2007-03-07 13:18:59 +0100116$branch ../.git
Santi Béjarac3ec0d2007-03-05 09:09:39 +0100117$branch ../.git one
118$branch ../.git one two
119$branch --tags ../.git
120$branch ../.git tag tag-one tag tag-three
121$branch ../.git tag tag-one-tree tag tag-three-file
122$branch ../.git one tag tag-one tag tag-three-file
123EOF
124done >> tests
125
126while read cmd
127do
128 case "$cmd" in
129 '' | '#'*) continue ;;
130 esac
131 test=`echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g'`
Johannes Sixt8586f982009-02-05 21:20:56 +0100132 pfx=`printf "%04d" $test_count`
Junio C Hamanobfdbee92008-08-08 02:26:28 -0700133 expect_f="$TEST_DIRECTORY/t5515/fetch.$test"
Junio C Hamanoa4666372008-03-26 01:17:07 -0700134 actual_f="$pfx-fetch.$test"
Junio C Hamanobfdbee92008-08-08 02:26:28 -0700135 expect_r="$TEST_DIRECTORY/t5515/refs.$test"
Junio C Hamanoa4666372008-03-26 01:17:07 -0700136 actual_r="$pfx-refs.$test"
Santi Béjarac3ec0d2007-03-05 09:09:39 +0100137
138 test_expect_success "$cmd" '
139 {
140 echo "# $cmd"
141 set x $cmd; shift
142 git symbolic-ref HEAD refs/heads/$1 ; shift
143 rm -f .git/FETCH_HEAD
Johan Herlandd0d12b42008-06-16 01:16:53 +0200144 git for-each-ref \
145 refs/heads refs/remotes/rem refs/tags |
146 while read val type refname
147 do
148 git update-ref -d "$refname" "$val"
149 done
Santi Béjarac3ec0d2007-03-05 09:09:39 +0100150 git fetch "$@" >/dev/null
151 cat .git/FETCH_HEAD
Junio C Hamanoa4666372008-03-26 01:17:07 -0700152 } >"$actual_f" &&
153 git show-ref >"$actual_r" &&
154 if test -f "$expect_f"
Santi Béjarac3ec0d2007-03-05 09:09:39 +0100155 then
Junio C Hamano3af82862008-05-23 22:28:56 -0700156 test_cmp "$expect_f" "$actual_f" &&
Junio C Hamanoa4666372008-03-26 01:17:07 -0700157 rm -f "$actual_f"
Santi Béjarac3ec0d2007-03-05 09:09:39 +0100158 else
159 # this is to help developing new tests.
Junio C Hamanoa4666372008-03-26 01:17:07 -0700160 cp "$actual_f" "$expect_f"
161 false
162 fi &&
163 if test -f "$expect_r"
164 then
Junio C Hamano3af82862008-05-23 22:28:56 -0700165 test_cmp "$expect_r" "$actual_r" &&
Junio C Hamanoa4666372008-03-26 01:17:07 -0700166 rm -f "$actual_r"
167 else
168 # this is to help developing new tests.
169 cp "$actual_r" "$expect_r"
Santi Béjarac3ec0d2007-03-05 09:09:39 +0100170 false
171 fi
172 '
173done < tests
174
175test_done