Skip to content

Commit 87bacd1

Browse files
committed
Move path/commit validation into GitFileHistory
This definitely belongs in the model layer, not in the executable.
1 parent ffa764b commit 87bacd1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

bin/git-browse

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,16 @@ import argparse
77
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
88

99
from gitbrowse.browser import GitBrowser
10-
from gitbrowse import git
1110

1211

1312
parser = argparse.ArgumentParser(add_help=False)
1413
parser.add_argument('rev', nargs='?', default='HEAD')
1514
parser.add_argument('file')
1615
args = parser.parse_args()
1716

18-
if not git.verify_revision(args.rev):
19-
sys.exit(1)
17+
try:
18+
browser = GitBrowser(args.file, args.rev)
19+
except ValueError as err:
20+
sys.exit(str(err))
2021

21-
if not git.verify_file(args.file):
22-
sys.exit("'%s' either does not exist, or is not tracked by git" % (
23-
args.file
24-
))
25-
26-
browser = GitBrowser(args.file, args.rev)
2722
browser.run()

gitbrowse/git.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ class GitFileHistory(object):
3535
"""
3636

3737
def __init__(self, path, start_commit):
38-
#TODO Validate path
39-
#TODO Validate commit
38+
if not verify_revision(start_commit):
39+
raise ValueError('%s is not a valid commit, branch, tag, etc.' % (
40+
start_commit,
41+
))
42+
43+
if not verify_file(path):
44+
raise ValueError('"%s" is not tracked by git' % (path, ))
4045

4146
self.path = path
4247

0 commit comments

Comments
 (0)