File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env python
22
3+ import sys
34import argparse
45import textwrap
56
@@ -55,6 +56,13 @@ parser.add_argument('file',
5556 help = 'the path to the file you want to examine' )
5657args = 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 ()
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments