aboutsummaryrefslogtreecommitdiffstats
path: root/git_deps/handler.py
blob: 2fe71ad7bc45e239021a07e4da85b4b93e04cf87 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python

from __future__ import print_function

import os
import re
import subprocess
import sys
from urlparse import urlparse, urljoin

def abort(msg, exitcode=1):
    print(msg, file=sys.stderr)
    sys.exit(exitcode)

def usage():
    abort("usage: git-handler URL")

def main(args):
    if len(args) != 1:
        usage()

    url = args[0]

    if url.scheme != 'gitfile':
        abort("URL must use gitfile:// scheme")

    repo = os.path.join(url.netloc, url.path)
    rev = url.fragment
    os.chdir(repo)

    subprocess.Popen(['gitk', '--all', '--select-commit=%s' % rev])

def run():
    main(sys.argv[1:])


if __name__ == "__main__":
    run()