Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork966
Expand file tree
/
Copy pathtest_remote.py
More file actions
653 lines (548 loc) · 26.3 KB
/
test_remote.py
File metadata and controls
653 lines (548 loc) · 26.3 KB
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
# test_remote.py
# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
importrandom
importtempfile
fromunittestimportskipIf
fromgitimport (
RemoteProgress,
FetchInfo,
Reference,
SymbolicReference,
Head,
Commit,
PushInfo,
RemoteReference,
TagReference,
Remote,
GitCommandError
)
fromgit.cmdimportGit
fromtest.libimport (
TestBase,
with_rw_repo,
with_rw_and_rw_remote_repo,
fixture,
GIT_DAEMON_PORT
)
fromgit.utilimportrmtree,HIDE_WINDOWS_FREEZE_ERRORS
importos.pathasosp
# assure we have repeatable results
random.seed(0)
classTestRemoteProgress(RemoteProgress):
__slots__= ("_seen_lines","_stages_per_op",'_num_progress_messages')
def__init__(self):
super(TestRemoteProgress,self).__init__()
self._seen_lines= []
self._stages_per_op= {}
self._num_progress_messages=0
def_parse_progress_line(self,line):
# we may remove the line later if it is dropped
# Keep it for debugging
self._seen_lines.append(line)
rval=super(TestRemoteProgress,self)._parse_progress_line(line)
returnrval
defline_dropped(self,line):
try:
self._seen_lines.remove(line)
exceptValueError:
pass
defupdate(self,op_code,cur_count,max_count=None,message=''):
# check each stage only comes once
op_id=op_code&self.OP_MASK
assertop_idin (self.COUNTING,self.COMPRESSING,self.WRITING)
ifop_code&self.WRITING>0:
ifop_code&self.BEGIN>0:
assertnotmessage,'should not have message when remote begins writing'
elifop_code&self.END>0:
assertmessage
assertnotmessage.startswith(', '),"Sanitize progress messages: '%s'"%message
assertnotmessage.endswith(', '),"Sanitize progress messages: '%s'"%message
self._stages_per_op.setdefault(op_id,0)
self._stages_per_op[op_id]=self._stages_per_op[op_id]| (op_code&self.STAGE_MASK)
ifop_code& (self.WRITING|self.END)== (self.WRITING|self.END):
assertmessage
# END check we get message
self._num_progress_messages+=1
defmake_assertion(self):
# we don't always receive messages
ifnotself._seen_lines:
return
# sometimes objects are not compressed which is okay
assertlen(self._seen_ops)in (2,3),len(self._seen_ops)
assertself._stages_per_op
# must have seen all stages
for_op,stagesinself._stages_per_op.items():
assertstages&self.STAGE_MASK==self.STAGE_MASK
# END for each op/stage
defassert_received_message(self):
assertself._num_progress_messages
classTestRemote(TestBase):
deftearDown(self):
importgc
gc.collect()
def_print_fetchhead(self,repo):
withopen(osp.join(repo.git_dir,"FETCH_HEAD")):
pass
def_do_test_fetch_result(self,results,remote):
# self._print_fetchhead(remote.repo)
self.assertGreater(len(results),0)
self.assertIsInstance(results[0],FetchInfo)
forinfoinresults:
self.assertIsInstance(info.note,str)
ifisinstance(info.ref,Reference):
self.assertTrue(info.flags)
# END reference type flags handling
self.assertIsInstance(info.ref, (SymbolicReference,Reference))
ifinfo.flags& (info.FORCED_UPDATE|info.FAST_FORWARD):
self.assertIsInstance(info.old_commit,Commit)
else:
self.assertIsNone(info.old_commit)
# END forced update checking
# END for each info
def_do_test_push_result(self,results,remote):
self.assertGreater(len(results),0)
self.assertIsInstance(results[0],PushInfo)
forinfoinresults:
self.assertTrue(info.flags)
self.assertIsInstance(info.summary,str)
ifinfo.old_commitisnotNone:
self.assertIsInstance(info.old_commit,Commit)
ifinfo.flags&info.ERROR:
has_one=False
forbitflagin (info.REJECTED,info.REMOTE_REJECTED,info.REMOTE_FAILURE):
has_one|=bool(info.flags&bitflag)
# END for each bitflag
self.assertTrue(has_one)
else:
# there must be a remote commit
ifinfo.flags&info.DELETED==0:
self.assertIsInstance(info.local_ref,Reference)
else:
self.assertIsNone(info.local_ref)
self.assertIn(type(info.remote_ref), (TagReference,RemoteReference))
# END error checking
# END for each info
def_do_test_fetch_info(self,repo):
self.assertRaises(ValueError,FetchInfo._from_line,repo,"nonsense",'')
self.assertRaises(
ValueError,FetchInfo._from_line,repo,"? [up to date] 0.1.7RC -> origin/0.1.7RC",'')
def_commit_random_file(self,repo):
# Create a file with a random name and random data and commit it to repo.
# Return the committed absolute file path
index=repo.index
new_file=self._make_file(osp.basename(tempfile.mktemp()),str(random.random()),repo)
index.add([new_file])
index.commit("Committing %s"%new_file)
returnnew_file
def_do_test_fetch(self,remote,rw_repo,remote_repo):
# specialized fetch testing to de-clutter the main test
self._do_test_fetch_info(rw_repo)
deffetch_and_test(remote,**kwargs):
progress=TestRemoteProgress()
kwargs['progress']=progress
res=remote.fetch(**kwargs)
progress.make_assertion()
self._do_test_fetch_result(res,remote)
returnres
# END fetch and check
defget_info(res,remote,name):
returnres["%s/%s"% (remote,name)]
# put remote head to master as it is guaranteed to exist
remote_repo.head.reference=remote_repo.heads.master
res=fetch_and_test(remote)
# all up to date
forinfoinres:
self.assertTrue(info.flags&info.HEAD_UPTODATE)
# rewind remote head to trigger rejection
# index must be false as remote is a bare repo
rhead=remote_repo.head
remote_commit=rhead.commit
rhead.reset("HEAD~2",index=False)
res=fetch_and_test(remote)
mkey="%s/%s"% (remote,'master')
master_info=res[mkey]
self.assertTrue(master_info.flags&FetchInfo.FORCED_UPDATE)
self.assertIsNotNone(master_info.note)
# normal fast forward - set head back to previous one
rhead.commit=remote_commit
res=fetch_and_test(remote)
self.assertTrue(res[mkey].flags&FetchInfo.FAST_FORWARD)
# new remote branch
new_remote_branch=Head.create(remote_repo,"new_branch")
res=fetch_and_test(remote)
new_branch_info=get_info(res,remote,new_remote_branch)
self.assertTrue(new_branch_info.flags&FetchInfo.NEW_HEAD)
# remote branch rename ( causes creation of a new one locally )
new_remote_branch.rename("other_branch_name")
res=fetch_and_test(remote)
other_branch_info=get_info(res,remote,new_remote_branch)
self.assertEqual(other_branch_info.ref.commit,new_branch_info.ref.commit)
# remove new branch
Head.delete(new_remote_branch.repo,new_remote_branch)
res=fetch_and_test(remote)
# deleted remote will not be fetched
self.assertRaises(IndexError,get_info,res,remote,new_remote_branch)
# prune stale tracking branches
stale_refs=remote.stale_refs
self.assertEqual(len(stale_refs),2)
self.assertIsInstance(stale_refs[0],RemoteReference)
RemoteReference.delete(rw_repo,*stale_refs)
# test single branch fetch with refspec including target remote
res=fetch_and_test(remote,refspec="master:refs/remotes/%s/master"%remote)
self.assertEqual(len(res),1)
self.assertTrue(get_info(res,remote,'master'))
# ... with respec and no target
res=fetch_and_test(remote,refspec='master')
self.assertEqual(len(res),1)
# ... multiple refspecs ... works, but git command returns with error if one ref is wrong without
# doing anything. This is new in later binaries
# res = fetch_and_test(remote, refspec=['master', 'fred'])
# self.assertEqual(len(res), 1)
# add new tag reference
rtag=TagReference.create(remote_repo,"1.0-RV_hello.there")
res=fetch_and_test(remote,tags=True)
tinfo=res[str(rtag)]
self.assertIsInstance(tinfo.ref,TagReference)
self.assertEqual(tinfo.ref.commit,rtag.commit)
self.assertTrue(tinfo.flags&tinfo.NEW_TAG)
# adjust the local tag commit
Reference.set_object(rtag,rhead.commit.parents[0].parents[0])
# as of git 2.20 one cannot clobber local tags that have changed without
# specifying --force, and the test assumes you can clobber, so...
force=None
ifrw_repo.git.version_info[:2]>= (2,20):
force=True
res=fetch_and_test(remote,tags=True,force=force)
tinfo=res[str(rtag)]
self.assertEqual(tinfo.commit,rtag.commit)
self.assertTrue(tinfo.flags&tinfo.TAG_UPDATE)
# delete remote tag - local one will stay
TagReference.delete(remote_repo,rtag)
res=fetch_and_test(remote,tags=True)
self.assertRaises(IndexError,get_info,res,remote,str(rtag))
# provoke to receive actual objects to see what kind of output we have to
# expect. For that we need a remote transport protocol
# Create a new UN-shared repo and fetch into it after we pushed a change
# to the shared repo
other_repo_dir=tempfile.mktemp("other_repo")
# must clone with a local path for the repo implementation not to freak out
# as it wants local paths only ( which I can understand )
other_repo=remote_repo.clone(other_repo_dir,shared=False)
remote_repo_url=osp.basename(remote_repo.git_dir)# git-daemon runs with appropriate `--base-path`.
remote_repo_url=Git.polish_url("git://localhost:%s/%s"% (GIT_DAEMON_PORT,remote_repo_url))
# put origin to git-url
other_origin=other_repo.remotes.origin
withother_origin.config_writerascw:
cw.set("url",remote_repo_url)
# it automatically creates alternates as remote_repo is shared as well.
# It will use the transport though and ignore alternates when fetching
# assert not other_repo.alternates # this would fail
# assure we are in the right state
rw_repo.head.reset(remote.refs.master,working_tree=True)
try:
self._commit_random_file(rw_repo)
remote.push(rw_repo.head.reference)
# here I would expect to see remote-information about packing
# objects and so on. Unfortunately, this does not happen
# if we are redirecting the output - git explicitly checks for this
# and only provides progress information to ttys
res=fetch_and_test(other_origin)
finally:
rmtree(other_repo_dir)
# END test and cleanup
def_assert_push_and_pull(self,remote,rw_repo,remote_repo):
# push our changes
lhead=rw_repo.head
# assure we are on master and it is checked out where the remote is
try:
lhead.reference=rw_repo.heads.master
exceptAttributeError:
# if the author is on a non-master branch, the clones might not have
# a local master yet. We simply create it
lhead.reference=rw_repo.create_head('master')
# END master handling
lhead.reset(remote.refs.master,working_tree=True)
# push without spec should fail ( without further configuration )
# well, works nicely
# self.assertRaises(GitCommandError, remote.push)
# simple file push
self._commit_random_file(rw_repo)
progress=TestRemoteProgress()
res=remote.push(lhead.reference,progress)
self.assertIsInstance(res,list)
self._do_test_push_result(res,remote)
progress.make_assertion()
# rejected - undo last commit
lhead.reset("HEAD~1")
res=remote.push(lhead.reference)
self.assertTrue(res[0].flags&PushInfo.ERROR)
self.assertTrue(res[0].flags&PushInfo.REJECTED)
self._do_test_push_result(res,remote)
# force rejected pull
res=remote.push('+%s'%lhead.reference)
self.assertEqual(res[0].flags&PushInfo.ERROR,0)
self.assertTrue(res[0].flags&PushInfo.FORCED_UPDATE)
self._do_test_push_result(res,remote)
# invalid refspec
self.assertRaises(GitCommandError,remote.push,"hellothere")
# push new tags
progress=TestRemoteProgress()
to_be_updated="my_tag.1.0RV"
new_tag=TagReference.create(rw_repo,to_be_updated)# @UnusedVariable
other_tag=TagReference.create(rw_repo,"my_obj_tag.2.1aRV",logmsg="my message")
res=remote.push(progress=progress,tags=True)
self.assertTrue(res[-1].flags&PushInfo.NEW_TAG)
progress.make_assertion()
self._do_test_push_result(res,remote)
# update push new tags
# Rejection is default
new_tag=TagReference.create(rw_repo,to_be_updated,reference='HEAD~1',force=True)
res=remote.push(tags=True)
self._do_test_push_result(res,remote)
self.assertTrue(res[-1].flags&PushInfo.REJECTED)
self.assertTrue(res[-1].flags&PushInfo.ERROR)
# push force this tag
res=remote.push("+%s"%new_tag.path)
self.assertEqual(res[-1].flags&PushInfo.ERROR,0)
self.assertTrue(res[-1].flags&PushInfo.FORCED_UPDATE)
# delete tag - have to do it using refspec
res=remote.push(":%s"%new_tag.path)
self._do_test_push_result(res,remote)
self.assertTrue(res[0].flags&PushInfo.DELETED)
# Currently progress is not properly transferred, especially not using
# the git daemon
# progress.assert_received_message()
# push new branch
new_head=Head.create(rw_repo,"my_new_branch")
progress=TestRemoteProgress()
res=remote.push(new_head,progress)
self.assertGreater(len(res),0)
self.assertTrue(res[0].flags&PushInfo.NEW_HEAD)
progress.make_assertion()
self._do_test_push_result(res,remote)
# rejected stale delete
force_with_lease="%s:0000000000000000000000000000000000000000"%new_head.path
res=remote.push(":%s"%new_head.path,force_with_lease=force_with_lease)
self.assertTrue(res[0].flags&PushInfo.ERROR)
self.assertTrue(res[0].flags&PushInfo.REJECTED)
self.assertIsNone(res[0].local_ref)
self._do_test_push_result(res,remote)
# delete new branch on the remote end and locally
res=remote.push(":%s"%new_head.path)
self._do_test_push_result(res,remote)
Head.delete(rw_repo,new_head)
self.assertTrue(res[-1].flags&PushInfo.DELETED)
# --all
res=remote.push(all=True)
self._do_test_push_result(res,remote)
remote.pull('master')
# cleanup - delete created tags and branches as we are in an innerloop on
# the same repository
TagReference.delete(rw_repo,new_tag,other_tag)
remote.push(":%s"%other_tag.path)
@skipIf(HIDE_WINDOWS_FREEZE_ERRORS,"FIXME: Freezes!")
@with_rw_and_rw_remote_repo('0.1.6')
deftest_base(self,rw_repo,remote_repo):
num_remotes=0
remote_set=set()
ran_fetch_test=False
forremoteinrw_repo.remotes:
num_remotes+=1
self.assertEqual(remote,remote)
self.assertNotEqual(str(remote),repr(remote))
remote_set.add(remote)
remote_set.add(remote)# should already exist
# REFS
refs=remote.refs
self.assertTrue(refs)
forrefinrefs:
self.assertEqual(ref.remote_name,remote.name)
self.assertTrue(ref.remote_head)
# END for each ref
# OPTIONS
# cannot use 'fetch' key anymore as it is now a method
foroptin ("url",):
val=getattr(remote,opt)
reader=remote.config_reader
assertreader.get(opt)==val
assertreader.get_value(opt,None)==val
# unable to write with a reader
self.assertRaises(IOError,reader.set,opt,"test")
# change value
withremote.config_writeraswriter:
new_val="myval"
writer.set(opt,new_val)
assertwriter.get(opt)==new_val
writer.set(opt,val)
assertwriter.get(opt)==val
assertgetattr(remote,opt)==val
# END for each default option key
# RENAME
other_name="totally_other_name"
prev_name=remote.name
self.assertEqual(remote.rename(other_name),remote)
self.assertNotEqual(prev_name,remote.name)
# multiple times
for_inrange(2):
self.assertEqual(remote.rename(prev_name).name,prev_name)
# END for each rename ( back to prev_name )
# PUSH/PULL TESTING
self._assert_push_and_pull(remote,rw_repo,remote_repo)
# FETCH TESTING
# Only for remotes - local cases are the same or less complicated
# as additional progress information will never be emitted
ifremote.name=="daemon_origin":
self._do_test_fetch(remote,rw_repo,remote_repo)
ran_fetch_test=True
# END fetch test
remote.update()
# END for each remote
self.assertTrue(ran_fetch_test)
self.assertTrue(num_remotes)
self.assertEqual(num_remotes,len(remote_set))
origin=rw_repo.remote('origin')
assertorigin==rw_repo.remotes.origin
# Verify we can handle prunes when fetching
# stderr lines look like this: x [deleted] (none) -> origin/experiment-2012
# These should just be skipped
# If we don't have a manual checkout, we can't actually assume there are any non-master branches
remote_repo.create_head("myone_for_deletion")
# Get the branch - to be pruned later
origin.fetch()
num_deleted=False
forbranchinremote_repo.heads:
ifbranch.name!='master':
branch.delete(remote_repo,branch,force=True)
num_deleted+=1
# end
# end for each branch
self.assertGreater(num_deleted,0)
self.assertEqual(len(rw_repo.remotes.origin.fetch(prune=True)),1,"deleted everything but master")
@with_rw_repo('HEAD',bare=True)
deftest_creation_and_removal(self,bare_rw_repo):
new_name="test_new_one"
arg_list= (new_name,"git@server:hello.git")
remote=Remote.create(bare_rw_repo,*arg_list)
self.assertEqual(remote.name,"test_new_one")
self.assertIn(remote,bare_rw_repo.remotes)
self.assertTrue(remote.exists())
# create same one again
self.assertRaises(GitCommandError,Remote.create,bare_rw_repo,*arg_list)
Remote.remove(bare_rw_repo,new_name)
self.assertTrue(remote.exists())# We still have a cache that doesn't know we were deleted by name
remote._clear_cache()
assertnotremote.exists()# Cache should be renewed now. This is an issue ...
forremoteinbare_rw_repo.remotes:
ifremote.name==new_name:
raiseAssertionError("Remote removal failed")
# END if deleted remote matches existing remote's name
# END for each remote
# Issue #262 - the next call would fail if bug wasn't fixed
bare_rw_repo.create_remote('bogus','/bogus/path',mirror='push')
deftest_fetch_info(self):
# assure we can handle remote-tracking branches
fetch_info_line_fmt="c437ee5deb8d00cf02f03720693e4c802e99f390not-for-merge%s '0.3' of "
fetch_info_line_fmt+="git://github.com/gitpython-developers/GitPython"
remote_info_line_fmt="* [new branch] nomatter -> %s"
self.assertRaises(ValueError,FetchInfo._from_line,self.rorepo,
remote_info_line_fmt%"refs/something/branch",
"269c498e56feb93e408ed4558c8138d750de8893\t\t/Users/ben/test/foo\n")
fi=FetchInfo._from_line(self.rorepo,
remote_info_line_fmt%"local/master",
fetch_info_line_fmt%'remote-tracking branch')
assertnotfi.ref.is_valid()
self.assertEqual(fi.ref.name,"local/master")
# handles non-default refspecs: One can specify a different path in refs/remotes
# or a special path just in refs/something for instance
fi=FetchInfo._from_line(self.rorepo,
remote_info_line_fmt%"subdir/tagname",
fetch_info_line_fmt%'tag')
self.assertIsInstance(fi.ref,TagReference)
assertfi.ref.path.startswith('refs/tags'),fi.ref.path
# it could be in a remote direcftory though
fi=FetchInfo._from_line(self.rorepo,
remote_info_line_fmt%"remotename/tags/tagname",
fetch_info_line_fmt%'tag')
self.assertIsInstance(fi.ref,TagReference)
assertfi.ref.path.startswith('refs/remotes/'),fi.ref.path
# it can also be anywhere !
tag_path="refs/something/remotename/tags/tagname"
fi=FetchInfo._from_line(self.rorepo,
remote_info_line_fmt%tag_path,
fetch_info_line_fmt%'tag')
self.assertIsInstance(fi.ref,TagReference)
self.assertEqual(fi.ref.path,tag_path)
# branches default to refs/remotes
fi=FetchInfo._from_line(self.rorepo,
remote_info_line_fmt%"remotename/branch",
fetch_info_line_fmt%'branch')
self.assertIsInstance(fi.ref,RemoteReference)
self.assertEqual(fi.ref.remote_name,'remotename')
# but you can force it anywhere, in which case we only have a references
fi=FetchInfo._from_line(self.rorepo,
remote_info_line_fmt%"refs/something/branch",
fetch_info_line_fmt%'branch')
asserttype(fi.ref)isReference,type(fi.ref)
self.assertEqual(fi.ref.path,"refs/something/branch")
deftest_uncommon_branch_names(self):
stderr_lines=fixture('uncommon_branch_prefix_stderr').decode('ascii').splitlines()
fetch_lines=fixture('uncommon_branch_prefix_FETCH_HEAD').decode('ascii').splitlines()
# The contents of the files above must be fetched with a custom refspec:
# +refs/pull/*:refs/heads/pull/*
res= [FetchInfo._from_line('ShouldntMatterRepo',stderr,fetch_line)
forstderr,fetch_lineinzip(stderr_lines,fetch_lines)]
self.assertGreater(len(res),0)
self.assertEqual(res[0].remote_ref_path,'refs/pull/1/head')
self.assertEqual(res[0].ref.path,'refs/heads/pull/1/head')
self.assertIsInstance(res[0].ref,Head)
@with_rw_repo('HEAD',bare=False)
deftest_multiple_urls(self,rw_repo):
# test addresses
test1='https://github.com/gitpython-developers/GitPython'
test2='https://github.com/gitpython-developers/gitdb'
test3='https://github.com/gitpython-developers/smmap'
remote=rw_repo.remotes[0]
# Testing setting a single URL
remote.set_url(test1)
self.assertEqual(list(remote.urls), [test1])
# Testing replacing that single URL
remote.set_url(test1)
self.assertEqual(list(remote.urls), [test1])
# Testing adding new URLs
remote.set_url(test2,add=True)
self.assertEqual(list(remote.urls), [test1,test2])
remote.set_url(test3,add=True)
self.assertEqual(list(remote.urls), [test1,test2,test3])
# Testing removing an URL
remote.set_url(test2,delete=True)
self.assertEqual(list(remote.urls), [test1,test3])
# Testing changing an URL
remote.set_url(test2,test3)
self.assertEqual(list(remote.urls), [test1,test2])
# will raise: fatal: --add --delete doesn't make sense
self.assertRaises(GitCommandError,remote.set_url,test2,add=True,delete=True)
# Testing on another remote, with the add/delete URL
remote=rw_repo.create_remote('another',url=test1)
remote.add_url(test2)
self.assertEqual(list(remote.urls), [test1,test2])
remote.add_url(test3)
self.assertEqual(list(remote.urls), [test1,test2,test3])
# Testing removing all the URLs
remote.delete_url(test2)
self.assertEqual(list(remote.urls), [test1,test3])
remote.delete_url(test1)
self.assertEqual(list(remote.urls), [test3])
# will raise fatal: Will not delete all non-push URLs
self.assertRaises(GitCommandError,remote.delete_url,test3)
deftest_fetch_error(self):
rem=self.rorepo.remote('origin')
withself.assertRaisesRegex(GitCommandError,"[Cc]ouldn't find remote ref __BAD_REF__"):
rem.fetch('__BAD_REF__')
@with_rw_repo('0.1.6',bare=False)
deftest_push_error(self,repo):
rem=repo.remote('origin')
withself.assertRaisesRegex(GitCommandError,"src refspec __BAD_REF__ does not match any"):
rem.push('__BAD_REF__')