Skip to content

Commit 12b9dc6

Browse files
committed
Remove unnecessary method
1 parent a44f094 commit 12b9dc6

File tree

3 files changed

+2
-27
lines changed

3 files changed

+2
-27
lines changed

modules/git/repo_branch.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package git
77
import (
88
"context"
99
"errors"
10-
"fmt"
1110
"strings"
1211
)
1312

@@ -25,24 +24,6 @@ func IsBranchExist(ctx context.Context, repoPath, name string) bool {
2524
return IsReferenceExist(ctx, repoPath, BranchPrefix+name)
2625
}
2726

28-
// GetHEADBranchName returns corresponding branch of HEAD.
29-
func (repo *Repository) GetHEADBranchName() (string, error) {
30-
if repo == nil {
31-
return "", fmt.Errorf("nil repo")
32-
}
33-
stdout, _, err := NewCommand("symbolic-ref", "HEAD").RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
34-
if err != nil {
35-
return "", err
36-
}
37-
stdout = strings.TrimSpace(stdout)
38-
39-
if !strings.HasPrefix(stdout, BranchPrefix) {
40-
return "", fmt.Errorf("invalid HEAD branch: %v", stdout)
41-
}
42-
43-
return stdout[len(BranchPrefix):], nil
44-
}
45-
4627
func GetDefaultBranch(ctx context.Context, repoPath string) (string, error) {
4728
stdout, _, err := NewCommand("symbolic-ref", "HEAD").RunStdString(ctx, &RunOpts{Dir: repoPath})
4829
if err != nil {

routers/api/v1/repo/commits.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,7 @@ func GetAllCommits(ctx *context.APIContext) {
180180
var baseCommit *git.Commit
181181
if len(sha) == 0 {
182182
// no sha supplied - use default branch
183-
headBranchName, err := ctx.Repo.GitRepo.GetHEADBranchName()
184-
if err != nil {
185-
ctx.APIErrorInternal(err)
186-
return
187-
}
188-
189-
baseCommit, err = ctx.Repo.GitRepo.GetBranchCommit(headBranchName)
183+
baseCommit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
190184
if err != nil {
191185
ctx.APIErrorInternal(err)
192186
return

services/repository/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
142142
if !repo.IsEmpty {
143143
if len(repo.DefaultBranch) == 0 {
144144
// Try to get HEAD branch and set it as default branch.
145-
headBranchName, err := gitRepo.GetHEADBranchName()
145+
headBranchName, err := git.GetDefaultBranch(ctx, repoPath)
146146
if err != nil {
147147
return repo, fmt.Errorf("GetHEADBranch: %w", err)
148148
}

0 commit comments

Comments
 (0)