From ae1650824cd50890837d04b310d8ab0f54d46912 Mon Sep 17 00:00:00 2001 From: Sina Siadat Date: Mon, 7 Sep 2015 01:04:35 +0430 Subject: [PATCH] Set IsBare true if migrated repo is empty. Executes `git log -1` and sets IsBare to true if stderr contains this string: fatal: bad default revision 'HEAD' --- models/repo.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/models/repo.go b/models/repo.go index 2835b6f9e3c..06c97baf24b 100644 --- a/models/repo.go +++ b/models/repo.go @@ -470,6 +470,12 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str return repo, fmt.Errorf("create update hook: %v", err) } + // Check if repository is empty. + _, stderr, err = com.ExecCmdDir(repoPath, "git", "log", "-1") + if err != nil && strings.Contains(stderr, "fatal: bad default revision 'HEAD'") { + repo.IsBare = true + } + // Check if repository has master branch, if so set it to default branch. gitRepo, err := git.OpenRepository(repoPath) if err != nil {