Skip to content

Commit 8dd51f1

Browse files
committed
Improved refparse error handling in case of out-of-bound indices
1 parent 7029773 commit 8dd51f1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

repo/fun.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,12 @@ def rev_parse(repo, rev):
190190
raise NotImplementedError("Support for additional @{...} modes not implemented")
191191
#END handle revlog index
192192

193-
entry = ref.log()[revlog_index]
193+
try:
194+
entry = ref.log()[revlog_index]
195+
except IndexError:
196+
raise BadObject("Invalid revlog index: %i" % revlog_index)
197+
#END handle index out of bound
198+
194199
obj = Object.new_from_sha(repo, hex_to_bin(entry.newhexsha))
195200

196201
# make it pass the following checks

test/test_repo.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -557,12 +557,19 @@ def test_rev_parse(self):
557557
# uses HEAD.ref by default
558558
assert rev_parse('@{0}') == head.commit
559559
if not head.is_detached:
560-
assert rev_parse('%s@{0}' % head.ref.name) == head.ref.commit
560+
refspec = '%s@{0}' % head.ref.name
561+
assert rev_parse(refspec) == head.ref.commit
562+
# all additional specs work as well
563+
assert rev_parse(refspec+"^{tree}") == head.commit.tree
564+
assert rev_parse(refspec+":CHANGES").type == 'blob'
561565
#END operate on non-detached head
562566

563567
# the last position
564568
assert rev_parse('@{1}') != head.commit
565569

570+
# position doesn't exist
571+
self.failUnlessRaises(BadObject, rev_parse, '@{10000}')
572+
566573
# currently, nothing more is supported
567574
self.failUnlessRaises(NotImplementedError, rev_parse, "@{1 week ago}")
568575

0 commit comments

Comments
 (0)