diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2025-03-15 19:48:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-15 19:48:59 -0700 |
commit | 0056fdb94201f54fcbb51d741a68b04bf41213fc (patch) | |
tree | 5185b6ad1d8c8560e8cb06cb83a60d6c8fc35620 /modules/gitrepo | |
parent | f11ac6bf3cb45e01080b1ec5bd9cbdd1ee5cda92 (diff) | |
download | gitea-0056fdb94201f54fcbb51d741a68b04bf41213fc.tar.gz gitea-0056fdb94201f54fcbb51d741a68b04bf41213fc.zip |
Move git references checking to gitrepo packages to reduce expose of repository path (#33891)
Diffstat (limited to 'modules/gitrepo')
-rw-r--r-- | modules/gitrepo/branch.go | 18 | ||||
-rw-r--r-- | modules/gitrepo/tag.go | 15 |
2 files changed, 33 insertions, 0 deletions
diff --git a/modules/gitrepo/branch.go b/modules/gitrepo/branch.go index 3336036248..9c4bdc5bdf 100644 --- a/modules/gitrepo/branch.go +++ b/modules/gitrepo/branch.go @@ -47,3 +47,21 @@ func GetDefaultBranch(ctx context.Context, repo Repository) (string, error) { func GetWikiDefaultBranch(ctx context.Context, repo Repository) (string, error) { return git.GetDefaultBranch(ctx, wikiPath(repo)) } + +// IsReferenceExist returns true if given reference exists in the repository. +func IsReferenceExist(ctx context.Context, repo Repository, name string) bool { + return git.IsReferenceExist(ctx, repoPath(repo), name) +} + +func IsWikiReferenceExist(ctx context.Context, repo Repository, name string) bool { + return git.IsReferenceExist(ctx, wikiPath(repo), name) +} + +// IsBranchExist returns true if given branch exists in the repository. +func IsBranchExist(ctx context.Context, repo Repository, name string) bool { + return IsReferenceExist(ctx, repo, git.BranchPrefix+name) +} + +func IsWikiBranchExist(ctx context.Context, repo Repository, name string) bool { + return IsWikiReferenceExist(ctx, repo, git.BranchPrefix+name) +} diff --git a/modules/gitrepo/tag.go b/modules/gitrepo/tag.go new file mode 100644 index 0000000000..58ed204a99 --- /dev/null +++ b/modules/gitrepo/tag.go @@ -0,0 +1,15 @@ +// Copyright 2025 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package gitrepo + +import ( + "context" + + "code.gitea.io/gitea/modules/git" +) + +// IsTagExist returns true if given tag exists in the repository. +func IsTagExist(ctx context.Context, repo Repository, name string) bool { + return IsReferenceExist(ctx, repo, git.TagPrefix+name) +} |