Skip to content

Commit f6102b3

Browse files
committed
Reference: reading of commit data is now safer and handles non-existing paths - previously it would run into a code-branch I forgot
1 parent ac4133f commit f6102b3

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

lib/git/refs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def _get_ref_info(self):
112112
# END for each packed ref
113113
# END handle packed refs
114114

115+
if tokens is None:
116+
raise ValueError("Reference at %r does not exist" % self.path)
117+
115118
# is it a reference ?
116119
if tokens[0] == 'ref:':
117120
return (None, tokens[1])
@@ -417,7 +420,6 @@ def rename(self, new_path, force=False):
417420
def _iter_items(cls, repo, common_path = None):
418421
if common_path is None:
419422
common_path = cls._common_path_default
420-
421423
rela_paths = set()
422424

423425
# walk loose refs
@@ -516,7 +518,7 @@ def __init__(self, repo, path):
516518
517519
"""
518520
if not path.startswith(self._common_path_default+'/'):
519-
raise ValueError("Cannot instantiate %s from path %s" % ( self.__class__.__name__, path ))
521+
raise ValueError("Cannot instantiate %r from path %s" % ( self.__class__.__name__, path ))
520522
super(Reference, self).__init__(repo, path)
521523

522524

lib/git/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def _has_lock(self):
135135
pid = int(fp.read())
136136
fp.close()
137137
except IOError:
138-
raise AssertionError("GitConfigParser has a lock but the lock file at %s could not be read" % lock_file)
138+
raise AssertionError("The lock file at %s could not be read" % lock_file)
139139

140140
if pid != os.getpid():
141141
raise AssertionError("We claim to own the lock at %s, but it was not owned by our process: %i" % (lock_file, os.getpid()))

test/git/test_refs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ def test_head_reset(self, rw_repo):
274274
assert ref_new_name.object == orig_obj
275275
assert ref_new_name == ref
276276
# END for each name type
277+
278+
# References that don't exist trigger an error if we want to access them
279+
self.failUnlessRaises(ValueError, getattr, Reference(rw_repo, "refs/doesntexist"), 'commit')
280+
277281
# exists, fail unless we force
278282
ex_ref_path = far_away_head.path
279283
self.failUnlessRaises(OSError, ref.rename, ex_ref_path)

0 commit comments

Comments
 (0)