summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--empty-repo/HEAD1
-rw-r--r--empty-repo/config4
-rw-r--r--empty-repo/description1
-rw-r--r--empty-repo/objects/.gitignore0
-rw-r--r--empty-repo/refs/.gitignore0
-rwxr-xr-xgit-mirror-cgit41
-rwxr-xr-xgit-mirror-gitlab-ce5
7 files changed, 40 insertions, 12 deletions
diff --git a/empty-repo/HEAD b/empty-repo/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/empty-repo/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/empty-repo/config b/empty-repo/config
new file mode 100644
index 0000000..07d359d
--- /dev/null
+++ b/empty-repo/config
@@ -0,0 +1,4 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
diff --git a/empty-repo/description b/empty-repo/description
new file mode 100644
index 0000000..498b267
--- /dev/null
+++ b/empty-repo/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/empty-repo/objects/.gitignore b/empty-repo/objects/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/empty-repo/objects/.gitignore
diff --git a/empty-repo/refs/.gitignore b/empty-repo/refs/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/empty-repo/refs/.gitignore
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)
diff --git a/git-mirror-gitlab-ce b/git-mirror-gitlab-ce
index 80f0b81..dc7a4db 100755
--- a/git-mirror-gitlab-ce
+++ b/git-mirror-gitlab-ce
@@ -125,6 +125,10 @@ class GitLabCE < GitMirrorBackend
mismatch = false
map.each do |key,val|
if self.info[key].to_s != val.to_s
+ if !mismatch
+ libremessages('msg2', 'Updating general metadata')
+ end
+ libremessages('plain', '%q: %q -> %q', key, self.info[key].to_s, val.to_s)
mismatch = true
end
end
@@ -132,7 +136,6 @@ class GitLabCE < GitMirrorBackend
libremessages('msg2', 'General metadata ok')
return nil
end
- libremessages('msg2', 'Updating general metadata')
req = Net::HTTP::Put.new(@gl.config['apiurl'] + "projects/" + CGI::escape(self.info["id"].to_s))
req.add_field("PRIVATE-TOKEN", @gl.config['apikey'])
req.add_field("Content-Type", "application/json")