-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patht-eg-5520-pull.sh
executable file
·302 lines (272 loc) · 7.72 KB
/
t-eg-5520-pull.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/bin/sh
test_description="tests of eg's pulling behavior"
. ./test-lib.sh
D=`pwd`
fgit="--git-dir=pullfrom/.git"
tgit="--git-dir=pullto/.git"
# Notes:
# git pull URL : pulls from HEAD (not master or whatever, but HEAD)
# git pull REMOTE : whine if branch.*.remote!=REMOTE || branch.*.merge unset
# git pull : needs branch.*.(merge|remote)
#
# Weird:
# 'git pull' or 'git pull origin' with origin set and branch.*.merge
# set correctly pulls from the origin repository (though listing url)
# and then whines:
# From file:///home/newren/otherhome/eg/t/trash directory....
# 07c68b0..3ad2682 bugfix -> origin/bugfix
# Your configuration specifies to merge the ref 'bugfix' from the
# remote, but no such ref was fetched.
# not knowing what to merge, asking the user to set
# branch.master.merge, which is already set.
#
# Cases:
# Plain pull (origin defined, unless otherwise specified):
# Into void
# Into non-void, origin not specified
# only branch.*.remote setup
# only branch.*.merge setup
# only branch.*.merge setup & origin not defined
# remote side has one branch
# remote side has two branches
# Pull w/ repo arg: (repeat for repo = remote & repo = url??)
# Into void
# only branch.*.remote setup
# only branch.*.merge setup
# fully setup, but mismatch of branch.*.remote
# remote side has one branch
# remote side has two branches
# Pull w/ --branch arg:
# Into void
# only branch.*.remote setup
# only branch.*.merge setup
# only branch.*.merge setup & origin not defined
# remote side has one branch
# remote side has two branches
mk_repo_pair () {
rm -rf pullfrom pullto &&
mkdir pullto &&
(
cd pullto &&
git init -q &&
git remote add origin ../pullfrom
) &&
mkdir pullfrom &&
(
cd pullfrom &&
git init -q &&
git symbolic-ref HEAD refs/heads/newbranch &&
echo one >foo && git add foo && git commit -q -m one &&
git symbolic-ref HEAD refs/heads/bugfix &&
rm .git/index &&
rm foo &&
echo content >bar && git add bar && git commit -q -m stuff
)
}
verify_pulled () {
remote_b=$1 &&
num_branches=$2 &&
t_master=$(git $tgit rev-parse refs/heads/master) &&
test_must_fail git $tgit show-ref -q -s --verify refs/heads/newbranch &&
test_must_fail git $tgit show-ref -q -s --verify refs/heads/bugfix &&
echo git $fgit show-ref -s --verify refs/heads/$remote_b &&
f_remote=$(git $fgit show-ref -s --verify refs/heads/$remote_b) &&
test "$t_master" = "$f_remote" &&
test $(git $tgit show-ref --head | wc -l) = "$num_branches"
}
test_expect_success 'pulling with direct URL' '
mk_repo_pair &&
(
cd pullto &&
git pull ../pullfrom # will merge from HEAD=bugfix
) &&
verify_pulled bugfix 2
'
cat > expect << EOF
Aborting: No repository specified, and "origin" is not set up as a remote
repository. Please specify a repository or setup "origin" by running
eg remote add origin URL
EOF
test_expect_success 'pull w/o origin setup and no branch.$branch.remote' '
mk_repo_pair &&
(
cd pullto &&
echo hi > world && git add world && git commit -m commitone &&
git remote rm origin &&
test_must_fail git pull > actual 2>&1
) &&
test_cmp expect pullto/actual
'
cat > expect << EOF
Aborting: It is not clear which remote branch to pull changes from. Please
retry, specifying which branch(es) you want to be merged into your current
branch. Existing remote branches of
origin
are
bugfix newbranch
EOF
test_expect_success 'pull w/o active branch & >1 remote branch' '
mk_repo_pair &&
(
cd pullto &&
echo hi > world && git add world && git commit -m commitone &&
git checkout HEAD^{commit} &&
test_must_fail git pull > actual 2>&1
) &&
test_cmp expect pullto/actual
'
test_expect_success 'pull when branch.$branch.remote unset & >1 remote branch' '
mk_repo_pair &&
(
cd pullto &&
test_must_fail git pull > actual 2>&1
) &&
test_cmp expect pullto/actual
'
test_expect_success 'pull when repo!=branch.$branch.remote & >1 remote branch' '
mk_repo_pair &&
(
cd pullto &&
git remote add foo ../pullfrom &&
git config branch.master.remote foo &&
git config branch.master.merge refs/heads/bugfix &&
test_must_fail git pull origin > actual 2>&1
) &&
test_cmp expect pullto/actual
'
cat > expect << EOF
fatal: 'foobarbaz' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
Aborting: Could not determine remote branches from repository 'foo'
EOF
test_expect_success 'pull when repo is bad remote' '
mk_repo_pair &&
(
cd pullto &&
git remote add foo foobarbaz &&
test_must_fail git pull foo > actual 2>&1
) &&
test_cmp expect pullto/actual
'
cat > expect << EOF
Aborting: It is not clear which remote branch to pull changes from. Please
retry, specifying which branch(es) you want to be merged into your current
branch. Existing remote branches of
foo
are
bugfix newbranch
EOF
test_expect_success 'pull when repo!=branch.$branch.remote & >1 remote branch' '
mk_repo_pair &&
(
cd pullto &&
git remote add foo ../pullfrom &&
git config branch.master.remote origin &&
git config branch.master.merge refs/heads/bugfix &&
test_must_fail git pull foo > actual 2>&1
) &&
test_cmp expect pullto/actual
'
test_expect_success 'pull when branch.$branch.merge unset & >1 remote branch' '
mk_repo_pair &&
(
cd pullto &&
git remote add foo ../pullfrom &&
git config branch.master.remote origin &&
test_must_fail git pull foo > actual 2>&1
) &&
test_cmp expect pullto/actual
'
test_expect_success 'pull when everything setup' '
mk_repo_pair &&
(
cd pullto &&
git remote add foo ../pullfrom &&
git config branch.master.remote foo &&
git config branch.master.merge refs/heads/bugfix &&
git pull
) &&
verify_pulled bugfix 4
'
nuke_branch () {
killit=$1 &&
git $fgit branch -D $killit
}
test_expect_success 'pull w/o active branch & 1 remote branch' '
mk_repo_pair &&
nuke_branch newbranch
(
cd pullto &&
echo hi > world && git add world && git commit -m commitone &&
git checkout HEAD^{commit} &&
git pull
) &&
test $(git $tgit rev-list --grep=Merge HEAD | wc -l) = "1"
'
test_expect_success 'pull when branch.$branch.remote unset & 1 remote branch' '
mk_repo_pair &&
nuke_branch newbranch
(
cd pullto &&
git pull
) &&
verify_pulled bugfix 2
'
test_expect_success 'pull when repo!=branch.$branch.remote & 1 remote branch' '
mk_repo_pair &&
nuke_branch newbranch
(
cd pullto &&
git remote add foo ../pullfrom &&
git config branch.master.remote foo &&
git config branch.master.merge refs/heads/bugfix &&
git pull origin
) &&
verify_pulled bugfix 2
'
test_expect_success 'pull when repo!=branch.$branch.remote & 1 remote branch' '
mk_repo_pair &&
nuke_branch newbranch
(
cd pullto &&
git remote add foo ../pullfrom &&
git config branch.master.remote origin &&
git config branch.master.merge refs/heads/bugfix &&
git pull foo
) &&
verify_pulled bugfix 2
'
test_expect_success 'pull when branch.$branch.merge unset & 1 remote branch' '
mk_repo_pair &&
nuke_branch newbranch
(
cd pullto &&
git remote add foo ../pullfrom &&
git config branch.master.remote origin &&
git pull foo
) &&
verify_pulled bugfix 2
'
cat > expect << EOF
Aborting: No repository specified, and "origin" is not set up as a remote
repository. Please specify a repository or setup "origin" by running
eg remote add origin URL
EOF
test_expect_success 'pull with --branch, no repo specified' '
mk_repo_pair &&
(
cd pullto &&
git remote rm origin &&
test_must_fail git pull --branch newbranch > actual 2>&1
) &&
test_cmp expect pullto/actual
'
test_expect_success 'pull with --branch, using default of origin' '
mk_repo_pair &&
(
cd pullto &&
git pull --branch newbranch
) &&
verify_pulled newbranch 2
'
test_done