Refactor repo.isBare to repo.isEmpty #5629 (#5714)

* Refactor repo.isBare to repo.isEmpty #5629

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Remove Sync call
This commit is contained in:
zeripath 2019-01-18 00:01:04 +00:00 committed by techknowlogick
parent 9edc829c17
commit 07802a2bc5
39 changed files with 125 additions and 81 deletions

View file

@ -187,7 +187,7 @@ type Repository struct {
NumReleases int `xorm:"-"`
IsPrivate bool `xorm:"INDEX"`
IsBare bool `xorm:"INDEX"`
IsEmpty bool `xorm:"INDEX"`
IsMirror bool `xorm:"INDEX"`
*Mirror `xorm:"-"`
@ -291,7 +291,7 @@ func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool)
FullName: repo.FullName(),
Description: repo.Description,
Private: repo.IsPrivate,
Empty: repo.IsBare,
Empty: repo.IsEmpty,
Size: int(repo.Size / 1024),
Fork: repo.IsFork,
Parent: parent,
@ -656,7 +656,7 @@ func (repo *Repository) CanUserFork(user *User) (bool, error) {
// CanEnablePulls returns true if repository meets the requirements of accepting pulls.
func (repo *Repository) CanEnablePulls() bool {
return !repo.IsMirror && !repo.IsBare
return !repo.IsMirror && !repo.IsEmpty
}
// AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
@ -954,13 +954,13 @@ func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, err
_, stderr, err := com.ExecCmdDir(repoPath, "git", "log", "-1")
if err != nil {
if strings.Contains(stderr, "fatal: bad default revision 'HEAD'") {
repo.IsBare = true
repo.IsEmpty = true
} else {
return repo, fmt.Errorf("check bare: %v - %s", err, stderr)
return repo, fmt.Errorf("check empty: %v - %s", err, stderr)
}
}
if !repo.IsBare {
if !repo.IsEmpty {
// Try to get HEAD branch and set it as default branch.
gitRepo, err := git.OpenRepository(repoPath)
if err != nil {
@ -999,7 +999,7 @@ func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, err
repo, err = CleanUpMigrateInfo(repo)
}
if err != nil && !repo.IsBare {
if err != nil && !repo.IsEmpty {
UpdateRepoIndexer(repo)
}
@ -1214,7 +1214,7 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts C
return fmt.Errorf("initRepository: path already exists: %s", repoPath)
}
// Init bare new repository.
// Init git bare new repository.
if err = git.InitRepository(repoPath, true); err != nil {
return fmt.Errorf("InitRepository: %v", err)
} else if err = createDelegateHooks(repoPath); err != nil {
@ -1249,7 +1249,7 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts C
}
if !opts.AutoInit {
repo.IsBare = true
repo.IsEmpty = true
}
repo.DefaultBranch = "master"