Browse Source

git-url: don't require github.com (support GH Enterprise)

raylu 8 years ago
parent
commit
edaf7b48f0
1 changed files with 17 additions and 20 deletions
  1. 17 20
      git-url

+ 17 - 20
git-url

@@ -28,23 +28,20 @@ hostname = parsed.hostname
 if hostname == 'github.com-private':
 	hostname = 'github.com'
 
-if hostname == 'github.com':
-	obj_type = 'tree'
-	if len(sys.argv) == 2:
-		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)
+obj_type = 'tree'
+if len(sys.argv) == 2:
+  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))