From 6437d0180b97a26319b50c2e22927dac7c94fcdd Mon Sep 17 00:00:00 2001 From: ᴜɴᴋɴᴡᴏɴ Date: Sun, 8 Mar 2020 19:09:31 +0800 Subject: git: migrate to github.com/gogs/git-module@v1.0.0 (#5958) * WIP * Finish `internal/db/git_diff.go` * FInish internal/db/mirror.go * Finish internal/db/pull.go * Finish internal/db/release.go * Finish internal/db/repo.go * Finish internal/db/repo_branch.go * Finish internal/db/repo_editor.go * Finish internal/db/update.go * Save my work * Add license header * Compile! * Merge master * Finish internal/cmd/hook.go * Finish internal/conf/static.go * Finish internal/context/repo.go * Finish internal/db/action.go * Finish internal/db/git_diff.go * Fix submodule URL inferring * Finish internal/db/mirror.go * Updat to beta.4 * css: update fonts * Finish internal/db/pull.go * Finish internal/db/release.go * Finish internal/db/repo_branch.go * Finish internal/db/wiki.go * gitutil: enhance infer submodule UR * Finish internal/route/api/v1/repo/commits.go * mirror: only collect branch commits after sync * mirror: fix tag support * Finish internal/db/repo.go * Finish internal/db/repo_editor.go * Finish internal/db/update.go * Finish internal/gitutil/pull_request.go * Make it compile * Finish internal/route/repo/setting.go * Finish internal/route/repo/branch.go * Finish internal/route/api/v1/repo/file.go * Finish internal/route/repo/download.go * Finish internal/route/repo/editor.go * Use helper * Finish internal/route/repo/issue.go * Finish internal/route/repo/pull.go * Finish internal/route/repo/release.go * Finish internal/route/repo/repo.go * Finish internal/route/repo/wiki.go * Finish internal/route/repo/commit.go * Finish internal/route/repo/view.go * Finish internal/gitutil/tag.go * go.sum --- internal/route/repo/setting.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'internal/route/repo/setting.go') diff --git a/internal/route/repo/setting.go b/internal/route/repo/setting.go index 405ead4f..bf463f4a 100644 --- a/internal/route/repo/setting.go +++ b/internal/route/repo/setting.go @@ -7,6 +7,7 @@ package repo import ( "fmt" "io/ioutil" + "os" "strings" "time" @@ -448,7 +449,7 @@ func SettingsBranches(c *context.Context) { // Filter out deleted branches branches := make([]string, 0, len(protectBranches)) for i := range protectBranches { - if c.Repo.GitRepo.IsBranchExist(protectBranches[i].Name) { + if c.Repo.GitRepo.HasBranch(protectBranches[i].Name) { branches = append(branches, protectBranches[i].Name) } } @@ -459,15 +460,12 @@ func SettingsBranches(c *context.Context) { func UpdateDefaultBranch(c *context.Context) { branch := c.Query("branch") - if c.Repo.GitRepo.IsBranchExist(branch) && + if c.Repo.GitRepo.HasBranch(branch) && c.Repo.Repository.DefaultBranch != branch { c.Repo.Repository.DefaultBranch = branch - if err := c.Repo.GitRepo.SetDefaultBranch(branch); err != nil { - if !git.IsErrUnsupportedVersion(err) { - c.Handle(500, "SetDefaultBranch", err) - return - } - + if _, err := c.Repo.GitRepo.SymbolicRef(git.SymbolicRefOptions{ + Ref: git.RefsHeads + branch, + }); err != nil { c.Flash.Warning(c.Tr("repo.settings.update_default_branch_unsupported")) c.Redirect(c.Repo.RepoLink + "/settings/branches") return @@ -485,7 +483,7 @@ func UpdateDefaultBranch(c *context.Context) { func SettingsProtectedBranch(c *context.Context) { branch := c.Params("*") - if !c.Repo.GitRepo.IsBranchExist(branch) { + if !c.Repo.GitRepo.HasBranch(branch) { c.NotFound() return } @@ -530,7 +528,7 @@ func SettingsProtectedBranch(c *context.Context) { func SettingsProtectedBranchPost(c *context.Context, f form.ProtectBranch) { branch := c.Params("*") - if !c.Repo.GitRepo.IsBranchExist(branch) { + if !c.Repo.GitRepo.HasBranch(branch) { c.NotFound() return } @@ -570,7 +568,7 @@ func SettingsGitHooks(c *context.Context) { c.Data["Title"] = c.Tr("repo.settings.githooks") c.Data["PageIsSettingsGitHooks"] = true - hooks, err := c.Repo.GitRepo.Hooks() + hooks, err := c.Repo.GitRepo.Hooks("custom_hooks") if err != nil { c.Handle(500, "Hooks", err) return @@ -586,9 +584,9 @@ func SettingsGitHooksEdit(c *context.Context) { c.Data["RequireSimpleMDE"] = true name := c.Params(":name") - hook, err := c.Repo.GitRepo.GetHook(name) + hook, err := c.Repo.GitRepo.Hook("custom_hooks", git.HookName(name)) if err != nil { - if err == git.ErrNotValidHook { + if err == os.ErrNotExist { c.Handle(404, "GetHook", err) } else { c.Handle(500, "GetHook", err) @@ -601,17 +599,16 @@ func SettingsGitHooksEdit(c *context.Context) { func SettingsGitHooksEditPost(c *context.Context) { name := c.Params(":name") - hook, err := c.Repo.GitRepo.GetHook(name) + hook, err := c.Repo.GitRepo.Hook("custom_hooks", git.HookName(name)) if err != nil { - if err == git.ErrNotValidHook { + if err == os.ErrNotExist { c.Handle(404, "GetHook", err) } else { c.Handle(500, "GetHook", err) } return } - hook.Content = c.Query("content") - if err = hook.Update(); err != nil { + if err = hook.Update(c.Query("content")); err != nil { c.Handle(500, "hook.Update", err) return } -- cgit v1.2.3