mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 20:02:09 +00:00
Handle more pathological branch and tag names (#11843)
* Handle more pathological branch and tag names Signed-off-by: Andrew Thornton <art27@cantab.net> * Fix failing test Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
6c2a59b50c
commit
0973c03601
8 changed files with 42 additions and 88 deletions
|
@ -6,6 +6,7 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
|
@ -102,7 +103,11 @@ func RestoreBranchPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := ctx.Repo.GitRepo.CreateBranch(deletedBranch.Name, deletedBranch.Commit); err != nil {
|
||||
if err := git.Push(ctx.Repo.Repository.RepoPath(), git.PushOptions{
|
||||
Remote: ctx.Repo.Repository.RepoPath(),
|
||||
Branch: fmt.Sprintf("%s:%s%s", deletedBranch.Commit, git.BranchPrefix, deletedBranch.Name),
|
||||
Env: models.PushingEnvironment(ctx.User, ctx.Repo.Repository),
|
||||
}); err != nil {
|
||||
if strings.Contains(err.Error(), "already exists") {
|
||||
ctx.Flash.Error(ctx.Tr("repo.branch.already_exists", deletedBranch.Name))
|
||||
return
|
||||
|
@ -112,12 +117,6 @@ func RestoreBranchPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := ctx.Repo.Repository.RemoveDeletedBranch(deletedBranch.ID); err != nil {
|
||||
log.Error("RemoveDeletedBranch: %v", err)
|
||||
ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", deletedBranch.Name))
|
||||
return
|
||||
}
|
||||
|
||||
// Don't return error below this
|
||||
if err := repofiles.PushUpdate(
|
||||
ctx.Repo.Repository,
|
||||
|
@ -216,7 +215,7 @@ func loadBranches(ctx *context.Context) []*Branch {
|
|||
}
|
||||
}
|
||||
|
||||
divergence, divergenceError := repofiles.CountDivergingCommits(ctx.Repo.Repository, branchName)
|
||||
divergence, divergenceError := repofiles.CountDivergingCommits(ctx.Repo.Repository, git.BranchPrefix+branchName)
|
||||
if divergenceError != nil {
|
||||
ctx.ServerError("CountDivergingCommits", divergenceError)
|
||||
return nil
|
||||
|
@ -331,6 +330,8 @@ func CreateBranch(ctx *context.Context, form auth.NewBranchForm) {
|
|||
var err error
|
||||
if ctx.Repo.IsViewBranch {
|
||||
err = repo_module.CreateNewBranch(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
|
||||
} else if ctx.Repo.IsViewTag {
|
||||
err = repo_module.CreateNewBranchFromCommit(ctx.User, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName)
|
||||
} else {
|
||||
err = repo_module.CreateNewBranchFromCommit(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue