diff options
Diffstat (limited to 'internal/route/repo/setting.go')
-rw-r--r-- | internal/route/repo/setting.go | 31 |
1 files changed, 14 insertions, 17 deletions
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 } |