|
|
@@ -10,23 +10,28 @@ def oneliner(*args):
|
|
|
|
|
|
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)
|
|
|
-remote_url = oneliner('git', 'config', 'remote.%s.url' % tracking_remote)
|
|
|
-relpath = oneliner('git', 'rev-parse', '--show-prefix')[:-1]
|
|
|
|
|
|
-if tracking_branch.startswith('refs/heads/'):
|
|
|
- tracking_branch = tracking_branch[len('refs/heads/'):]
|
|
|
+tag = None
|
|
|
+if local_branch.startswith('tags/'):
|
|
|
+ tag = local_branch[5:]
|
|
|
+ remote_url = oneliner('git', 'config', 'remote.origin.url')
|
|
|
else:
|
|
|
- raise Exception("can't handle " + tracking_branch)
|
|
|
+ tracking_branch = oneliner('git', 'config', 'branch.%s.merge' % local_branch)
|
|
|
+ if tracking_branch.startswith('refs/heads/'):
|
|
|
+ tracking_branch = tracking_branch[len('refs/heads/'):]
|
|
|
+ else:
|
|
|
+ raise Exception("can't handle " + tracking_branch)
|
|
|
+
|
|
|
+ tracking_remote = oneliner('git', 'config', 'branch.%s.remote' % local_branch)
|
|
|
+ remote_url = oneliner('git', 'config', 'remote.%s.url' % tracking_remote)
|
|
|
+
|
|
|
+relpath = oneliner('git', 'rev-parse', '--show-prefix')[:-1]
|
|
|
|
|
|
remote_url = re.sub(r'^(.+@.+):(.+)$', r'ssh://\1/\2', remote_url)
|
|
|
if remote_url.endswith('.git'):
|
|
|
remote_url = remote_url[:-len('.git')]
|
|
|
parsed = urllib.parse.urlparse(remote_url)
|
|
|
hostname = parsed.hostname
|
|
|
-if hostname == 'github.com-private':
|
|
|
- hostname = 'github.com'
|
|
|
|
|
|
obj_type = 'tree'
|
|
|
if len(sys.argv) == 2:
|
|
|
@@ -43,5 +48,8 @@ def url_for(treeish):
|
|
|
else:
|
|
|
return dir_url
|
|
|
|
|
|
-print(url_for(tracking_branch))
|
|
|
+if tag is not None:
|
|
|
+ print(url_for(tag))
|
|
|
+else:
|
|
|
+ print(url_for(tracking_branch))
|
|
|
print(url_for(commit))
|