Skip to content

Commit 9fa3aaf

Browse files
committed
Verify the git revision before launching UI.
This has the added benefit of checking that we're in a Git repo.
1 parent 777ed90 commit 9fa3aaf

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

git-browse

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import argparse
44
import textwrap
55

66
from gitbrowse.browser import GitBrowser
7+
from gitbrowse import git
78

89

910
parser = argparse.ArgumentParser(
@@ -54,5 +55,6 @@ parser.add_argument('file',
5455
help='the path to the file you want to examine')
5556
args = parser.parse_args()
5657

57-
browser = GitBrowser(args.file, args.rev)
58-
browser.run()
58+
if git.verify_revision(args.rev):
59+
browser = GitBrowser(args.file, args.rev)
60+
browser.run()

gitbrowse/git.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,17 @@ def _build_line_mappings(self, start, finish):
273273
finish_ln += 1
274274

275275
return forward, backward
276+
277+
278+
def verify_revision(rev):
279+
"""
280+
Verifies that a revision is valid in the current working directory,
281+
and returns True or False accordingly.
282+
283+
Errors are not supressed, so if the revision is bad or the CWD isn't
284+
a Git repository then Git's error message will be output.
285+
"""
286+
status = os.system('git rev-parse --verify --no-revs %s' % (
287+
rev
288+
))
289+
return status == 0

0 commit comments

Comments
 (0)