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

Commitb1a2271

Browse files
committed
refs: Added is_valid method to SymbolicReference base class
1 parentbc66da0 commitb1a2271

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

‎lib/git/refs.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,19 @@ def _set_reference(self, ref):
214214
# alias
215215
ref=reference
216216

217+
defis_valid(self):
218+
"""
219+
Returns
220+
True if the reference is valid, hence it can be read and points to
221+
a valid object or reference.
222+
"""
223+
try:
224+
self.commit
225+
except (OSError,ValueError):
226+
returnFalse
227+
else:
228+
returnTrue
229+
217230
@property
218231
defis_detached(self):
219232
"""

‎test/git/test_refs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ def test_refs(self):
6666
types_found.add(type(ref))
6767
assertlen(types_found)==3
6868

69+
deftest_is_valid(self):
70+
assertReference(self.rorepo,'refs/doesnt/exist').is_valid()==False
71+
assertself.rorepo.head.is_valid()
72+
assertself.rorepo.head.reference.is_valid()
73+
assertSymbolicReference(self.rorepo,'hellothere').is_valid()==False
74+
6975
@with_rw_repo('0.1.6')
7076
deftest_head_reset(self,rw_repo):
7177
cur_head=rw_repo.head

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp