aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorSina Siadat <siadat@gmail.com>2015-09-07 01:04:35 +0430
committerSina Siadat <siadat@gmail.com>2015-09-07 02:20:51 +0430
commitae1650824cd50890837d04b310d8ab0f54d46912 (patch)
treead414b79119a59caa25d8f62ab4a1ab593adcacc /models
parent00767a0522606cd504d81d35fa1d9e9c1e34610c (diff)
downloadgitea-ae1650824cd50890837d04b310d8ab0f54d46912.tar.gz
gitea-ae1650824cd50890837d04b310d8ab0f54d46912.zip
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'
Diffstat (limited to 'models')
-rw-r--r--models/repo.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/models/repo.go b/models/repo.go
index 2835b6f9e3..06c97baf24 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 {