mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-05 09:55:20 +02:00
chore: Refactor Is{Reference,Branch}Exist
(#8425)
- Instead of invoking a new git command to check if a reference exists, use the already opened git repository that uses a batch check to check if the reference exists. - Instead of invoking a new git command to check if a branch exists, use the already opened git repository that uses a batch check to check if the branch exists. - Do not depend on `IsReferenceExist` as its no longer used by any other function. - Specify `--quiet` to not waste Git's time on printing something we do not use. - Run it via `Run` so no buffers are created for stdout and stderr. - Add a test that verifies `IsBranchExist` works and does not work for other types of references. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8425 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
212e8ac348
commit
74981d9e97
6 changed files with 21 additions and 13 deletions
|
@ -594,7 +594,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
|||
isPlainRule := !git_model.IsRuleNameSpecial(ruleName)
|
||||
var isBranchExist bool
|
||||
if isPlainRule {
|
||||
isBranchExist = git.IsBranchExist(ctx.Req.Context(), ctx.Repo.Repository.RepoPath(), ruleName)
|
||||
isBranchExist = ctx.Repo.GitRepo.IsBranchExist(ruleName)
|
||||
}
|
||||
|
||||
protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, ruleName)
|
||||
|
@ -982,7 +982,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
|||
isPlainRule := !git_model.IsRuleNameSpecial(bpName)
|
||||
var isBranchExist bool
|
||||
if isPlainRule {
|
||||
isBranchExist = git.IsBranchExist(ctx.Req.Context(), ctx.Repo.Repository.RepoPath(), bpName)
|
||||
isBranchExist = ctx.Repo.GitRepo.IsBranchExist(bpName)
|
||||
}
|
||||
|
||||
if isBranchExist {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue