|
|
@@ -8,6 +8,7 @@ import urllib.parse
|
|
|
def oneliner(*args):
|
|
|
return subprocess.check_output(args, universal_newlines=True).strip()
|
|
|
|
|
|
+commit = oneliner('git', 'rev-parse', 'HEAD')
|
|
|
local_branch = oneliner('git', 'name-rev', '--name-only', 'HEAD')
|
|
|
tracking_remote = oneliner('git', 'config', 'branch.%s.remote' % local_branch)
|
|
|
tracking_branch = oneliner('git', 'config', 'branch.%s.merge' % local_branch)
|
|
|
@@ -28,13 +29,22 @@ if hostname == 'github.com-private':
|
|
|
hostname = 'github.com'
|
|
|
|
|
|
if hostname == 'github.com':
|
|
|
- repo_url = urllib.parse.urlunparse(('https', hostname, parsed.path, '', '', ''))
|
|
|
- dir_url = '%s/tree/%s' % (repo_url, tracking_branch)
|
|
|
- if relpath:
|
|
|
- dir_url = '%s/%s' % (dir_url, relpath)
|
|
|
+ obj_type = 'tree'
|
|
|
if len(sys.argv) == 2:
|
|
|
- print('%s/%s' % (dir_url, sys.argv[1]))
|
|
|
- else:
|
|
|
- print(dir_url)
|
|
|
+ obj_type = 'blob'
|
|
|
+
|
|
|
+ repo_url = urllib.parse.urlunparse(('https', hostname, parsed.path, '', '', ''))
|
|
|
+
|
|
|
+ def url_for(treeish):
|
|
|
+ dir_url = '%s/%s/%s' % (repo_url, obj_type, treeish)
|
|
|
+ if relpath:
|
|
|
+ dir_url = '%s/%s' % (dir_url, relpath)
|
|
|
+ if len(sys.argv) == 2:
|
|
|
+ return '%s/%s' % (dir_url, sys.argv[1])
|
|
|
+ else:
|
|
|
+ return dir_url
|
|
|
+
|
|
|
+ print(url_for(tracking_branch))
|
|
|
+ print(url_for(commit))
|
|
|
else:
|
|
|
raise Exception("can't handle " + parsed.hostname)
|