diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-01-14 11:38:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-14 11:38:04 +0800 |
commit | 2677d071f911fb91f382acfedaedc251bd807f70 (patch) | |
tree | 61d48125ff6e509e5ffe385b23fdc14fb454b9e6 /routers/repo | |
parent | bca367cecc6004957a952bb6222b9bbdc868e784 (diff) | |
download | gitea-2677d071f911fb91f382acfedaedc251bd807f70.tar.gz gitea-2677d071f911fb91f382acfedaedc251bd807f70.zip |
Move newbranch to standalone package (#9627)
* Move newbranch to standalone package
* move branch functions to modules to avoid dependencies cycles
* fix tests
* fix lint
* fix lint
Diffstat (limited to 'routers/repo')
-rw-r--r-- | routers/repo/branch.go | 7 | ||||
-rw-r--r-- | routers/repo/editor.go | 5 |
2 files changed, 7 insertions, 5 deletions
diff --git a/routers/repo/branch.go b/routers/repo/branch.go index df6e0bf21f..88bbe2be56 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/repofiles" + repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/util" "gopkg.in/src-d/go-git.v4/plumbing" ) @@ -175,7 +176,7 @@ func deleteBranch(ctx *context.Context, branchName string) error { } func loadBranches(ctx *context.Context) []*Branch { - rawBranches, err := ctx.Repo.Repository.GetBranches() + rawBranches, err := repo_module.GetBranches(ctx.Repo.Repository) if err != nil { ctx.ServerError("GetBranches", err) return nil @@ -324,9 +325,9 @@ func CreateBranch(ctx *context.Context, form auth.NewBranchForm) { var err error if ctx.Repo.IsViewBranch { - err = ctx.Repo.Repository.CreateNewBranch(ctx.User, ctx.Repo.BranchName, form.NewBranchName) + err = repo_module.CreateNewBranch(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName) } else { - err = ctx.Repo.Repository.CreateNewBranchFromCommit(ctx.User, ctx.Repo.BranchName, form.NewBranchName) + err = repo_module.CreateNewBranchFromCommit(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName) } if err != nil { if models.IsErrTagAlreadyExists(err) { diff --git a/routers/repo/editor.go b/routers/repo/editor.go index fec5728525..82c74ba75f 100644 --- a/routers/repo/editor.go +++ b/routers/repo/editor.go @@ -19,6 +19,7 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/repofiles" + repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/upload" "code.gitea.io/gitea/modules/util" @@ -534,7 +535,7 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) { } if oldBranchName != branchName { - if _, err := ctx.Repo.Repository.GetBranch(branchName); err == nil { + if _, err := repo_module.GetBranch(ctx.Repo.Repository, branchName); err == nil { ctx.Data["Err_NewBranchName"] = true ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchName), tplUploadFile, &form) return @@ -679,7 +680,7 @@ func GetUniquePatchBranchName(ctx *context.Context) string { prefix := ctx.User.LowerName + "-patch-" for i := 1; i <= 1000; i++ { branchName := fmt.Sprintf("%s%d", prefix, i) - if _, err := ctx.Repo.Repository.GetBranch(branchName); err != nil { + if _, err := repo_module.GetBranch(ctx.Repo.Repository, branchName); err != nil { if git.IsErrBranchNotExist(err) { return branchName } |