From b9fe143cf2503a180a636e131928735c4266b01f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 19 Jun 2017 13:52:46 -0400 Subject: cgit: fix default branch detection on empty repos --- git-mirror-cgit | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/git-mirror-cgit b/git-mirror-cgit index 5e6cfc6..5c56993 100755 --- a/git-mirror-cgit +++ b/git-mirror-cgit @@ -33,11 +33,17 @@ class Cgit < GitMirrorBackend def cmd_get_meta(path) doc = self.getHTML(path) - head = open(@config['url']+(path+'/HEAD')).read + empty = (doc.css('.error').text == "Repository seems to be empty") + if empty + default_branch = 'master' + else + head = open(@config['url']+(path+'/HEAD')).read + default_branch = head.split("\n")[0].sub(/^ref: /, '').sub(/^refs\/heads\//, '') + end return { 'description' => doc.css('#header .sub')[0].text, 'owner' => doc.css('#header .sub')[1].text, - 'default-branch' => head.split("\n")[0].sub(/^ref: /, '').sub(/^refs\/heads\//, ''), + 'default-branch' => default_branch, } end -- cgit v1.2.3