Skip to content

Commit

Permalink
Refactor repo.isBare to repo.isEmpty #5629 (#5714)
Browse files Browse the repository at this point in the history
* Refactor repo.isBare to repo.isEmpty #5629

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

* Remove Sync call
  • Loading branch information
zeripath authored and techknowlogick committed Jan 18, 2019
1 parent 9edc829 commit 07802a2
Show file tree
Hide file tree
Showing 39 changed files with 125 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import (
"code.gitea.io/gitea/models"
)

func TestBareRepo(t *testing.T) {
func TestEmptyRepo(t *testing.T) {
prepareTestEnv(t)
subpaths := []string{
"commits/master",
"raw/foo",
"commit/1ae57b34ccf7e18373",
"graph",
}
bareRepo := models.AssertExistsAndLoadBean(t, &models.Repository{}, models.Cond("is_bare = ?", true)).(*models.Repository)
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: bareRepo.OwnerID}).(*models.User)
emptyRepo := models.AssertExistsAndLoadBean(t, &models.Repository{}, models.Cond("is_empty = ?", true)).(*models.Repository)
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: emptyRepo.OwnerID}).(*models.User)
for _, subpath := range subpaths {
req := NewRequestf(t, "GET", "/%s/%s/%s", owner.Name, bareRepo.Name, subpath)
req := NewRequestf(t, "GET", "/%s/%s/%s", owner.Name, emptyRepo.Name, subpath)
MakeRequest(t, req, http.StatusNotFound)
}
}
8 changes: 4 additions & 4 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion models/fixtures/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
owner_id: 2
lower_name: repo15
name: repo15
is_bare: true
is_empty: true

-
id: 16
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions models/migrations/v78.go
Original file line number Diff line number Diff line change
@@ -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()
}
18 changes: 9 additions & 9 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion modules/context/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func APIContexter() macaron.Handler {
func ReferencesGitRepo() macaron.Handler {
return func(ctx *APIContext) {
// Empty repository does not have reference information.
if ctx.Repo.Repository.IsBare {
if ctx.Repo.Repository.IsEmpty {
return
}

Expand Down
10 changes: 5 additions & 5 deletions modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func repoAssignment(ctx *Context, repo *models.Repository) {

ctx.Repo.Repository = repo
ctx.Data["RepoName"] = ctx.Repo.Repository.Name
ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare
ctx.Data["IsEmptyRepo"] = ctx.Repo.Repository.IsEmpty
}

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

// repo is bare and display enable
if ctx.Repo.Repository.IsBare {
// repo is empty and display enable
if ctx.Repo.Repository.IsEmpty {
ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
return
}
Expand Down Expand Up @@ -520,7 +520,7 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
func RepoRefByType(refType RepoRefType) macaron.Handler {
return func(ctx *Context) {
// Empty repository does not have reference information.
if ctx.Repo.Repository.IsBare {
if ctx.Repo.Repository.IsEmpty {
return
}

Expand Down Expand Up @@ -549,7 +549,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
ctx.ServerError("GetBranches", err)
return
} else if len(brs) == 0 {
err = fmt.Errorf("No branches in non-bare repository %s",
err = fmt.Errorf("No branches in non-empty repository %s",
ctx.Repo.GitRepo.Path)
ctx.ServerError("GetBranches", err)
return
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_cs-CZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ quick_guide=Krátká příručka
clone_this_repo=Naklonovat tento repozitář
create_new_repo_command=Vytvořit nový repozitář na příkazové řádce
push_exist_repo=Nahrání existujícího repozitáře z příkazové řádky
bare_message=Tento repozitář nemá žádný obsah.
empty_message=Tento repozitář nemá žádný obsah.
code=Zdrojový kód
code.desc=Přístup ke zdrojovým kódům, souborům, revizím a větvím.
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_de-DE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ quick_guide=Kurzanleitung
clone_this_repo=Dieses Repository klonen
create_new_repo_command=Erstelle ein neues Repository von der Kommandozeile aus
push_exist_repo=Bestehendes Repository via Kommandozeile pushen
bare_message=Dieses Repository hat noch keinen Inhalt.
empty_message=Dieses Repository hat noch keinen Inhalt.

code=Code
code.desc=Zugriff auf Quellcode, Dateien, Commits und Branches.
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ quick_guide = Quick Guide
clone_this_repo = Clone this repository
create_new_repo_command = Creating a new repository on the command line
push_exist_repo = Pushing an existing repository from the command line
bare_message = This repository does not contain any content.
empty_message = This repository does not contain any content.
code = Code
code.desc = Access source code, files, commits and branches.
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_es-ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ quick_guide=Guía rápida
clone_this_repo=Clonar este repositorio
create_new_repo_command=Crear un nuevo repositorio desde línea de comandos
push_exist_repo=Hacer push de un repositorio existente desde línea de comandos
bare_message=Este repositorio no contiene ningún contenido.
empty_message=Este repositorio no contiene ningún contenido.

code=Código
branch=Rama
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_fr-FR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ quick_guide=Introduction rapide
clone_this_repo=Cloner ce dépôt
create_new_repo_command=Création d'un nouveau dépôt en ligne de commande
push_exist_repo=Soumission d'un dépôt existant par ligne de commande
bare_message=Ce dépôt ne contient aucune information.
empty_message=Ce dépôt ne contient aucune information.
code=Code
code.desc=Accéder au code source, fichiers, révisions et branches.
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_hu-HU.ini
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ quick_guide=Gyors útmutató
clone_this_repo=Tároló klónozása
create_new_repo_command=Egy új tároló létrehozása a parancssorból
push_exist_repo=Meglévő tároló feltöltése parancssorból
bare_message=A tároló nem tartalmaz semmit, üres.
empty_message=A tároló nem tartalmaz semmit, üres.

code=Kód
branch=Ág
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_id-ID.ini
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ quick_guide=Panduan Cepat
clone_this_repo=Klon repositori ini
create_new_repo_command=Membuat repositori baru pada baris perintah
push_exist_repo=Mendorong sebuah repositori yang ada di baris perintah
bare_message=Repositori ini tidak berisi konten apapun.
empty_message=Repositori ini tidak berisi konten apapun.

code=Kode
branch=Cabang
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_it-IT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ quick_guide=Guida rapida
clone_this_repo=Clona questo repository
create_new_repo_command=Creazione di un nuovo repository da riga di comando
push_exist_repo=Push di un repository esistente da riga di comando
bare_message=Questo repository non contiene alcun contenuto.
empty_message=Questo repository non contiene alcun contenuto.
code=Codice
code.desc=Accedi al codice sorgente, file, commits e branches.
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_ja-JP.ini
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ quick_guide=クイック ガイド
clone_this_repo=このリポジトリのクローンを作成
create_new_repo_command=コマンドラインから新しいリポジトリを作成
push_exist_repo=コマンドラインから既存のリポジトリをプッシュ
bare_message=このリポジトリには内容がありません。
empty_message=このリポジトリには内容がありません。

code=コード
code.desc=ソースコード、ファイル、コミット、ブランチにアクセス。
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_ko-KR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ quick_guide=퀵 가이드
clone_this_repo=이 저장소 복제
create_new_repo_command=커맨드 라인에서 새 레포리지터리 생성
push_exist_repo=커맨드라인에서 기존 레포지터리 푸시
bare_message=이 레포지터리에는 아무것도 없습니다.
empty_message=이 레포지터리에는 아무것도 없습니다.

code=코드
branch=브렌치
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_lv-LV.ini
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ quick_guide=Īsa pamācība
clone_this_repo=Klonēt šo repozitoriju
create_new_repo_command=Izveidot jaunu repozitoriju komandrindā
push_exist_repo=Nosūtīt izmaiņas no komandrindas eksistējošam repozitorijam
bare_message=Repozitorijs ir tukšs.
empty_message=Repozitorijs ir tukšs.

code=Kods
code.desc=Piekļūt pirmkodam, failiem, revīzijām un atzariem.
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_nl-NL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ quick_guide=Snelstart gids
clone_this_repo=Kloon deze repository
create_new_repo_command=Maak een nieuwe repository aan vanaf de console
push_exist_repo=Push een bestaande repositorie vanaf de console
bare_message=Deze repository bevat geen inhoud.
empty_message=Deze repository bevat geen inhoud.

code=Code
branch=Branch
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_pl-PL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ quick_guide=Skrócona instrukcja
clone_this_repo=Klonuj repozytorium
create_new_repo_command=Tworzenie nowego repozytorium z linii poleceń
push_exist_repo=Wypychanie istniejącego repozytorium z linii poleceń
bare_message=Repozytorium jest puste.
empty_message=Repozytorium jest puste.

code=Kod
branch=Gałąź
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_pt-BR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ quick_guide=Guia Rápido
clone_this_repo=Clonar este repositório
create_new_repo_command=Criando um novo repositório por linha de comando
push_exist_repo=Realizando push para um repositório existente por linha de comando
bare_message=Este repositório está vazio.
empty_message=Este repositório está vazio.

code=Código
code.desc=Acesso a código-fonte, arquivos, commits e branches.
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_ru-RU.ini
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ quick_guide=Краткое руководство
clone_this_repo=Клонировать репозиторий
create_new_repo_command=Создать новый репозиторий из командной строки
push_exist_repo=Push существующего репозитория из командной строки
bare_message=В репозитории нет файлов.
empty_message=В репозитории нет файлов.
code=Код
code.desc=Исходный код, файлы, коммиты и ветки.
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_sv-SE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ quick_guide=Snabbguide
clone_this_repo=Klona detta repo
create_new_repo_command=Skapa en ny utvecklingskatalog på kommandoraden
push_exist_repo=Pusha en existerande utvecklingskatalog från kommandoraden
bare_message=Denna utvecklingskatalog är tom.
empty_message=Denna utvecklingskatalog är tom.
code=Kod
code.desc=Se källkod, filer, commits och brancher.
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_tr-TR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ quick_guide=Hızlı Başlangıç Kılavuzu
clone_this_repo=Bu depoyu klonla
create_new_repo_command=Komut satırında yeni bir depo oluşturuluyor
push_exist_repo=Komut satırından mevcut bir depo itiliyor
bare_message=Bu depo herhangi bir içerik içermiyor.
empty_message=Bu depo herhangi bir içerik içermiyor.
code=Kod
branch=Dal
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_uk-UA.ini
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ quick_guide=Короткий посібник
clone_this_repo=Кнонувати цей репозиторій
create_new_repo_command=Створити новий репозиторій з командного рядка
push_exist_repo=Опублікувати існуючий репозиторій з командного рядка
bare_message=Цей репозиторій порожній.
empty_message=Цей репозиторій порожній.
code=Код
code.desc=Доступ до коду, файлів, комітів та гілок.
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_zh-CN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ quick_guide=快速帮助
clone_this_repo=克隆当前仓库
create_new_repo_command=从命令行创建一个新的仓库
push_exist_repo=从命令行推送已经创建的仓库
bare_message=这个家伙很懒,什么都没有推送。
empty_message=这个家伙很懒,什么都没有推送。
code=代码
code.desc=查看源码、文件、提交和分支。
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_zh-HK.ini
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ quick_guide=快速幫助
clone_this_repo=複製當前儲存庫
create_new_repo_command=從命令列建立新儲存庫。
push_exist_repo=從命令列推送已存在的儲存庫
bare_message=此儲存庫未包含任何內容。
empty_message=此儲存庫未包含任何內容。

code=程式碼
branch=分支
Expand Down
Loading

0 comments on commit 07802a2

Please sign in to comment.