Skip to content

Commit 8314d97

Browse files
committed
Verify that the file exists and is in git.
1 parent 9fa3aaf commit 8314d97

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

git-browse

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22

3+
import sys
34
import argparse
45
import textwrap
56

@@ -55,6 +56,13 @@ parser.add_argument('file',
5556
help='the path to the file you want to examine')
5657
args = parser.parse_args()
5758

58-
if git.verify_revision(args.rev):
59-
browser = GitBrowser(args.file, args.rev)
60-
browser.run()
59+
if not git.verify_revision(args.rev):
60+
sys.exit(1)
61+
62+
if not git.verify_file(args.file):
63+
sys.exit("'%s' either does not exist, or is not tracked by git" % (
64+
args.file
65+
))
66+
67+
browser = GitBrowser(args.file, args.rev)
68+
browser.run()

gitbrowse/git.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,13 @@ def verify_revision(rev):
287287
rev
288288
))
289289
return status == 0
290+
291+
292+
def verify_file(path):
293+
"""
294+
Verifies that a given file is tracked by Git and returns true or false
295+
accordingly.
296+
"""
297+
p = os.popen('git ls-files -- %s' % path)
298+
matching_files = p.readlines()
299+
return len(matching_files) > 0

0 commit comments

Comments
 (0)