Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf7b7eb6

Browse files
committed
Added Remote.exists() method, and test.Fixesgitpython-developers#229
1 parentc7887c6 commitf7b7eb6

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

‎git/remote.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,19 @@ def __ne__(self, other):
397397
def__hash__(self):
398398
returnhash(self.name)
399399

400+
defexists(self):
401+
""":return: True if this is a valid, existing remote.
402+
Valid remotes have an entry in the repository's configuration"""
403+
try:
404+
self.config_reader.get('url')
405+
returnTrue
406+
exceptcp.NoOptionError:
407+
# we have the section at least ...
408+
returnTrue
409+
exceptcp.NoSectionError:
410+
returnFalse
411+
# end
412+
400413
@classmethod
401414
defiter_items(cls,repo):
402415
""":return: Iterator yielding Remote objects of the given repository"""

‎git/repo/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,10 @@ def remotes(self):
250250
defremote(self,name='origin'):
251251
""":return: Remote with the specified name
252252
:raise ValueError: if no remote with such a name exists"""
253-
returnRemote(self,name)
253+
r=Remote(self,name)
254+
ifnotr.exists():
255+
raiseValueError("Remote named '%s' didn't exist"%name)
256+
returnr
254257

255258
#{ Submodules
256259

‎git/test/test_repo.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
Reference,
2626
GitDB,
2727
Submodule,
28-
GitCmdObjectDB
28+
GitCmdObjectDB,
29+
Remote
2930
)
3031
fromgit.utilimportjoin_path_native
3132
fromgit.excimportBadObject
@@ -673,3 +674,7 @@ def last_commit(repo, rev, path):
673674
last_commit(repo,'master','git/test/test_base.py')
674675
# end for each repository type
675676
# end for each iteration
677+
678+
deftest_remote_method(self):
679+
self.failUnlessRaises(ValueError,self.rorepo.remote,'foo-blue')
680+
assertisinstance(self.rorepo.remote(name='origin'),Remote)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp