Skip to content

Commit 07802a2

Browse files
zeripathtechknowlogick
authored andcommitted
Refactor repo.isBare to repo.isEmpty #5629 (#5714)
* Refactor repo.isBare to repo.isEmpty #5629 Signed-off-by: Andrew Thornton <[email protected]> * Remove Sync call
1 parent 9edc829 commit 07802a2

39 files changed

+125
-81
lines changed

integrations/bare_repo_test.go renamed to integrations/empty_repo_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ import (
1111
"code.gitea.io/gitea/models"
1212
)
1313

14-
func TestBareRepo(t *testing.T) {
14+
func TestEmptyRepo(t *testing.T) {
1515
prepareTestEnv(t)
1616
subpaths := []string{
1717
"commits/master",
1818
"raw/foo",
1919
"commit/1ae57b34ccf7e18373",
2020
"graph",
2121
}
22-
bareRepo := models.AssertExistsAndLoadBean(t, &models.Repository{}, models.Cond("is_bare = ?", true)).(*models.Repository)
23-
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: bareRepo.OwnerID}).(*models.User)
22+
emptyRepo := models.AssertExistsAndLoadBean(t, &models.Repository{}, models.Cond("is_empty = ?", true)).(*models.Repository)
23+
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: emptyRepo.OwnerID}).(*models.User)
2424
for _, subpath := range subpaths {
25-
req := NewRequestf(t, "GET", "/%s/%s/%s", owner.Name, bareRepo.Name, subpath)
25+
req := NewRequestf(t, "GET", "/%s/%s/%s", owner.Name, emptyRepo.Name, subpath)
2626
MakeRequest(t, req, http.StatusNotFound)
2727
}
2828
}

models/action.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,13 +574,13 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
574574

575575
refName := git.RefEndName(opts.RefFullName)
576576

577-
// Change default branch and bare status only if pushed ref is non-empty branch.
578-
if repo.IsBare && opts.NewCommitID != git.EmptySHA && strings.HasPrefix(opts.RefFullName, git.BranchPrefix) {
577+
// Change default branch and empty status only if pushed ref is non-empty branch.
578+
if repo.IsEmpty && opts.NewCommitID != git.EmptySHA && strings.HasPrefix(opts.RefFullName, git.BranchPrefix) {
579579
repo.DefaultBranch = refName
580-
repo.IsBare = false
580+
repo.IsEmpty = false
581581
}
582582

583-
// Change repository bare status and update last updated time.
583+
// Change repository empty status and update last updated time.
584584
if err = UpdateRepository(repo, false); err != nil {
585585
return fmt.Errorf("UpdateRepository: %v", err)
586586
}

models/fixtures/repository.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
owner_id: 2
176176
lower_name: repo15
177177
name: repo15
178-
is_bare: true
178+
is_empty: true
179179

180180
-
181181
id: 16

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ var migrations = []Migration{
208208
NewMigration("add pull request rebase with merge commit", addPullRequestRebaseWithMerge),
209209
// v77 -> v78
210210
NewMigration("add theme to users", addUserDefaultTheme),
211+
// v78 -> v79
212+
NewMigration("rename repo is_bare to repo is_empty", renameRepoIsBareToIsEmpty),
211213
}
212214

213215
// Migrate database to current version

models/migrations/v78.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"fmt"
9+
"strings"
10+
11+
"code.gitea.io/gitea/models"
12+
13+
"github.com/go-xorm/xorm"
14+
)
15+
16+
func renameRepoIsBareToIsEmpty(x *xorm.Engine) error {
17+
type Repository struct {
18+
ID int64 `xorm:"pk autoincr"`
19+
IsBare bool
20+
IsEmpty bool `xorm:"INDEX"`
21+
}
22+
23+
sess := x.NewSession()
24+
defer sess.Close()
25+
if err := sess.Begin(); err != nil {
26+
return err
27+
}
28+
var err error
29+
if models.DbCfg.Type == "mssql" {
30+
_, err = sess.Query("EXEC sp_rename 'repository.is_bare', 'is_empty', 'COLUMN'")
31+
} else {
32+
_, err = sess.Query("ALTER TABLE \"repository\" RENAME COLUMN \"is_bare\" TO \"is_empty\";")
33+
}
34+
if err != nil {
35+
if strings.Contains(err.Error(), "no such column") {
36+
return nil
37+
}
38+
return fmt.Errorf("select repositories: %v", err)
39+
}
40+
41+
return sess.Commit()
42+
}

models/repo.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ type Repository struct {
187187
NumReleases int `xorm:"-"`
188188

189189
IsPrivate bool `xorm:"INDEX"`
190-
IsBare bool `xorm:"INDEX"`
190+
IsEmpty bool `xorm:"INDEX"`
191191

192192
IsMirror bool `xorm:"INDEX"`
193193
*Mirror `xorm:"-"`
@@ -291,7 +291,7 @@ func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool)
291291
FullName: repo.FullName(),
292292
Description: repo.Description,
293293
Private: repo.IsPrivate,
294-
Empty: repo.IsBare,
294+
Empty: repo.IsEmpty,
295295
Size: int(repo.Size / 1024),
296296
Fork: repo.IsFork,
297297
Parent: parent,
@@ -656,7 +656,7 @@ func (repo *Repository) CanUserFork(user *User) (bool, error) {
656656

657657
// CanEnablePulls returns true if repository meets the requirements of accepting pulls.
658658
func (repo *Repository) CanEnablePulls() bool {
659-
return !repo.IsMirror && !repo.IsBare
659+
return !repo.IsMirror && !repo.IsEmpty
660660
}
661661

662662
// 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
954954
_, stderr, err := com.ExecCmdDir(repoPath, "git", "log", "-1")
955955
if err != nil {
956956
if strings.Contains(stderr, "fatal: bad default revision 'HEAD'") {
957-
repo.IsBare = true
957+
repo.IsEmpty = true
958958
} else {
959-
return repo, fmt.Errorf("check bare: %v - %s", err, stderr)
959+
return repo, fmt.Errorf("check empty: %v - %s", err, stderr)
960960
}
961961
}
962962

963-
if !repo.IsBare {
963+
if !repo.IsEmpty {
964964
// Try to get HEAD branch and set it as default branch.
965965
gitRepo, err := git.OpenRepository(repoPath)
966966
if err != nil {
@@ -999,7 +999,7 @@ func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, err
999999
repo, err = CleanUpMigrateInfo(repo)
10001000
}
10011001

1002-
if err != nil && !repo.IsBare {
1002+
if err != nil && !repo.IsEmpty {
10031003
UpdateRepoIndexer(repo)
10041004
}
10051005

@@ -1214,7 +1214,7 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts C
12141214
return fmt.Errorf("initRepository: path already exists: %s", repoPath)
12151215
}
12161216

1217-
// Init bare new repository.
1217+
// Init git bare new repository.
12181218
if err = git.InitRepository(repoPath, true); err != nil {
12191219
return fmt.Errorf("InitRepository: %v", err)
12201220
} else if err = createDelegateHooks(repoPath); err != nil {
@@ -1249,7 +1249,7 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts C
12491249
}
12501250

12511251
if !opts.AutoInit {
1252-
repo.IsBare = true
1252+
repo.IsEmpty = true
12531253
}
12541254

12551255
repo.DefaultBranch = "master"

modules/context/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func APIContexter() macaron.Handler {
124124
func ReferencesGitRepo() macaron.Handler {
125125
return func(ctx *APIContext) {
126126
// Empty repository does not have reference information.
127-
if ctx.Repo.Repository.IsBare {
127+
if ctx.Repo.Repository.IsEmpty {
128128
return
129129
}
130130

modules/context/repo.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func repoAssignment(ctx *Context, repo *models.Repository) {
234234

235235
ctx.Repo.Repository = repo
236236
ctx.Data["RepoName"] = ctx.Repo.Repository.Name
237-
ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare
237+
ctx.Data["IsEmptyRepo"] = ctx.Repo.Repository.IsEmpty
238238
}
239239

240240
// RepoIDAssignment returns a macaron handler which assigns the repo to the context.
@@ -370,8 +370,8 @@ func RepoAssignment() macaron.Handler {
370370
ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.ID, repo.ID)
371371
}
372372

373-
// repo is bare and display enable
374-
if ctx.Repo.Repository.IsBare {
373+
// repo is empty and display enable
374+
if ctx.Repo.Repository.IsEmpty {
375375
ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
376376
return
377377
}
@@ -520,7 +520,7 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
520520
func RepoRefByType(refType RepoRefType) macaron.Handler {
521521
return func(ctx *Context) {
522522
// Empty repository does not have reference information.
523-
if ctx.Repo.Repository.IsBare {
523+
if ctx.Repo.Repository.IsEmpty {
524524
return
525525
}
526526

@@ -549,7 +549,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
549549
ctx.ServerError("GetBranches", err)
550550
return
551551
} else if len(brs) == 0 {
552-
err = fmt.Errorf("No branches in non-bare repository %s",
552+
err = fmt.Errorf("No branches in non-empty repository %s",
553553
ctx.Repo.GitRepo.Path)
554554
ctx.ServerError("GetBranches", err)
555555
return

options/locale/locale_cs-CZ.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ quick_guide=Krátká příručka
578578
clone_this_repo=Naklonovat tento repozitář
579579
create_new_repo_command=Vytvořit nový repozitář na příkazové řádce
580580
push_exist_repo=Nahrání existujícího repozitáře z příkazové řádky
581-
bare_message=Tento repozitář nemá žádný obsah.
581+
empty_message=Tento repozitář nemá žádný obsah.
582582
583583
code=Zdrojový kód
584584
code.desc=Přístup ke zdrojovým kódům, souborům, revizím a větvím.

options/locale/locale_de-DE.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ quick_guide=Kurzanleitung
572572
clone_this_repo=Dieses Repository klonen
573573
create_new_repo_command=Erstelle ein neues Repository von der Kommandozeile aus
574574
push_exist_repo=Bestehendes Repository via Kommandozeile pushen
575-
bare_message=Dieses Repository hat noch keinen Inhalt.
575+
empty_message=Dieses Repository hat noch keinen Inhalt.
576576

577577
code=Code
578578
code.desc=Zugriff auf Quellcode, Dateien, Commits und Branches.

0 commit comments

Comments
 (0)