aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-03-08 15:30:10 +0800
committerGitHub <noreply@github.com>2024-03-08 15:30:10 +0800
commit25b842df261452a29570ba89ffc3a4842d73f68c (patch)
tree225cddc07630f491e3efb9976fb57d0d31adb38a /modules
parenta1f5dd767729e30d07ab42fda80c19f30a72679f (diff)
downloadgitea-25b842df261452a29570ba89ffc3a4842d73f68c.tar.gz
gitea-25b842df261452a29570ba89ffc3a4842d73f68c.zip
Move get/set default branch from git package to gitrepo package to hide repopath (#29126)
Diffstat (limited to 'modules')
-rw-r--r--modules/git/repo_branch.go11
-rw-r--r--modules/gitrepo/branch.go17
2 files changed, 19 insertions, 9 deletions
diff --git a/modules/git/repo_branch.go b/modules/git/repo_branch.go
index 979c5dec91..552ae2bb8c 100644
--- a/modules/git/repo_branch.go
+++ b/modules/git/repo_branch.go
@@ -55,15 +55,8 @@ func (repo *Repository) GetHEADBranch() (*Branch, error) {
}, nil
}
-// SetDefaultBranch sets default branch of repository.
-func (repo *Repository) SetDefaultBranch(name string) error {
- _, _, err := NewCommand(repo.Ctx, "symbolic-ref", "HEAD").AddDynamicArguments(BranchPrefix + name).RunStdString(&RunOpts{Dir: repo.Path})
- return err
-}
-
-// GetDefaultBranch gets default branch of repository.
-func (repo *Repository) GetDefaultBranch() (string, error) {
- stdout, _, err := NewCommand(repo.Ctx, "symbolic-ref", "HEAD").RunStdString(&RunOpts{Dir: repo.Path})
+func GetDefaultBranch(ctx context.Context, repoPath string) (string, error) {
+ stdout, _, err := NewCommand(ctx, "symbolic-ref", "HEAD").RunStdString(&RunOpts{Dir: repoPath})
if err != nil {
return "", err
}
diff --git a/modules/gitrepo/branch.go b/modules/gitrepo/branch.go
index dcaf92668d..e13a4c82e1 100644
--- a/modules/gitrepo/branch.go
+++ b/modules/gitrepo/branch.go
@@ -30,3 +30,20 @@ func GetBranchCommitID(ctx context.Context, repo Repository, branch string) (str
return gitRepo.GetBranchCommitID(branch)
}
+
+// SetDefaultBranch sets default branch of repository.
+func SetDefaultBranch(ctx context.Context, repo Repository, name string) error {
+ _, _, err := git.NewCommand(ctx, "symbolic-ref", "HEAD").
+ AddDynamicArguments(git.BranchPrefix + name).
+ RunStdString(&git.RunOpts{Dir: repoPath(repo)})
+ return err
+}
+
+// GetDefaultBranch gets default branch of repository.
+func GetDefaultBranch(ctx context.Context, repo Repository) (string, error) {
+ return git.GetDefaultBranch(ctx, repoPath(repo))
+}
+
+func GetWikiDefaultBranch(ctx context.Context, repo Repository) (string, error) {
+ return git.GetDefaultBranch(ctx, wikiPath(repo))
+}