From 31933c806f2041cd95b1d863bee31b35a642fd35 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 19 Apr 2017 12:55:24 -0400 Subject: Add changes that had been staged on my server but never committed. --- git-mirror-cgit | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'git-mirror-cgit') 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) -- cgit v1.2.3