summaryrefslogtreecommitdiff
path: root/git-mirror-cgit
diff options
context:
space:
mode:
Diffstat (limited to 'git-mirror-cgit')
-rwxr-xr-xgit-mirror-cgit41
1 files changed, 30 insertions, 11 deletions
diff --git a/git-mirror-cgit b/git-mirror-cgit
index b932788..5e6cfc6 100755
--- a/git-mirror-cgit
+++ b/git-mirror-cgit
@@ -27,8 +27,12 @@ class Cgit < GitMirrorBackend
return nil
end
+ def getHTML(path)
+ Nokogiri::HTML(open(@config['url']+path))
+ end
+
def cmd_get_meta(path)
- doc = Nokogiri::HTML(open(@config['url']+path))
+ doc = self.getHTML(path)
head = open(@config['url']+(path+'/HEAD')).read
return {
'description' => doc.css('#header .sub')[0].text,
@@ -41,21 +45,36 @@ class Cgit < GitMirrorBackend
raise "no can do"
end
- def urls(path)
- doc = Nokogiri::HTML(open(@config['url']+path))
- return doc.css('a[rel="vcs-git"]').map{|a| a['href']}
- end
-
def cmd_push_url(path)
+ urls = self.getHTML(path).css('a[rel="vcs-git"]').map{|a| a['href']}
+
prefs = ['ssh', 'https', 'http', 'git']
- return self.urls(path).sort_by{|u| prefs.index(u.split(':', 2)[0])}.first
+ return urls.sort_by{|u| prefs.index(URI(u).scheme)}.first
end
def cmd_pull_url(path)
- # prefer https ahead of git because of a bug in git-daemon
- # with '~'.
- prefs = ['https', 'git', 'http', 'ssh']
- return self.urls(path).sort_by{|u| prefs.index(u.split(':', 2)[0])}.first
+ doc = self.getHTML(path)
+ urls = doc.css('a[rel="vcs-git"]').map{|a| a['href']}
+ empty = (doc.css('.error').text == "Repository seems to be empty")
+
+ prefs = ['git', 'https', 'http', 'file', 'ssh', 'git-broken', 'https-broken', 'http-broken']
+
+ if empty
+ urls.push('file://' + File.dirname(__FILE__) + '/empty-repo')
+ end
+ return urls.sort_by{|u|
+ u = URI(u)
+ scheme = u.scheme
+ # work around a bug in git-daemon
+ if u.scheme == 'git' and u.path.start_with?('/~')
+ scheme += '-broken'
+ end
+ # work around a bug in cgit
+ if u.scheme.start_with?('http') and empty
+ scheme += '-broken'
+ end
+ prefs.index(scheme)
+ }.first
end
def cmd_repo_mode(path)