* Refactor repo.isBare to repo.isEmpty #5629 Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove Sync call
This commit is contained in:
parent
9edc829c17
commit
07802a2bc5
39 changed files with 125 additions and 81 deletions
|
@ -574,13 +574,13 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
|
|||
|
||||
refName := git.RefEndName(opts.RefFullName)
|
||||
|
||||
// Change default branch and bare status only if pushed ref is non-empty branch.
|
||||
if repo.IsBare && opts.NewCommitID != git.EmptySHA && strings.HasPrefix(opts.RefFullName, git.BranchPrefix) {
|
||||
// Change default branch and empty status only if pushed ref is non-empty branch.
|
||||
if repo.IsEmpty && opts.NewCommitID != git.EmptySHA && strings.HasPrefix(opts.RefFullName, git.BranchPrefix) {
|
||||
repo.DefaultBranch = refName
|
||||
repo.IsBare = false
|
||||
repo.IsEmpty = false
|
||||
}
|
||||
|
||||
// Change repository bare status and update last updated time.
|
||||
// Change repository empty status and update last updated time.
|
||||
if err = UpdateRepository(repo, false); err != nil {
|
||||
return fmt.Errorf("UpdateRepository: %v", err)
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@
|
|||
owner_id: 2
|
||||
lower_name: repo15
|
||||
name: repo15
|
||||
is_bare: true
|
||||
is_empty: true
|
||||
|
||||
-
|
||||
id: 16
|
||||
|
|
|
@ -208,6 +208,8 @@ var migrations = []Migration{
|
|||
NewMigration("add pull request rebase with merge commit", addPullRequestRebaseWithMerge),
|
||||
// v77 -> v78
|
||||
NewMigration("add theme to users", addUserDefaultTheme),
|
||||
// v78 -> v79
|
||||
NewMigration("rename repo is_bare to repo is_empty", renameRepoIsBareToIsEmpty),
|
||||
}
|
||||
|
||||
// Migrate database to current version
|
||||
|
|
42
models/migrations/v78.go
Normal file
42
models/migrations/v78.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
func renameRepoIsBareToIsEmpty(x *xorm.Engine) error {
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
IsBare bool
|
||||
IsEmpty bool `xorm:"INDEX"`
|
||||
}
|
||||
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
var err error
|
||||
if models.DbCfg.Type == "mssql" {
|
||||
_, err = sess.Query("EXEC sp_rename 'repository.is_bare', 'is_empty', 'COLUMN'")
|
||||
} else {
|
||||
_, err = sess.Query("ALTER TABLE \"repository\" RENAME COLUMN \"is_bare\" TO \"is_empty\";")
|
||||
}
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "no such column") {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("select repositories: %v", err)
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
}
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue