This commit is contained in:
Lunny Xiao 2024-09-03 21:53:41 -07:00
parent 3ecf362783
commit 078edf8615
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 6 additions and 3 deletions

View File

@ -29,14 +29,15 @@ func GetBranchCommitID(ctx context.Context, repo Repository, branch string) (str
return "", err return "", err
} }
defer gitRepo.Close() defer gitRepo.Close()
return gitRepo.GetRefCommitID(branch) return gitRepo.GetRefCommitID(git.BranchPrefix + branch)
} }
// SetDefaultBranch sets default branch of repository. // SetDefaultBranch sets default branch of repository.
func SetDefaultBranch(ctx context.Context, repo Repository, name string) error { func SetDefaultBranch(ctx context.Context, repo Repository, name string) error {
cmd := git.NewCommand(ctx, "symbolic-ref", "HEAD"). cmd := git.NewCommand(ctx, "symbolic-ref", "HEAD").
AddDynamicArguments(git.BranchPrefix + name) AddDynamicArguments(git.BranchPrefix + name)
return RunGitCmd(ctx, repo, cmd, &git.RunOpts{}) _, _, err := RunGitCmdStdString(ctx, repo, cmd, &git.RunOpts{})
return err
} }
// GetDefaultBranch gets default branch of repository. // GetDefaultBranch gets default branch of repository.

View File

@ -6,6 +6,7 @@ package gitrepo
import ( import (
"context" "context"
"io" "io"
"path/filepath"
"strings" "strings"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
@ -48,7 +49,8 @@ func repositoryFromContext(ctx context.Context, repo Repository) *git.Repository
} }
if gitRepo, ok := value.(*git.Repository); ok && gitRepo != nil { if gitRepo, ok := value.(*git.Repository); ok && gitRepo != nil {
if strings.HasSuffix(gitRepo.Path, repoRelativePath(repo)) { relativePath := filepath.Join(strings.ToLower(repo.GetOwnerName()), strings.ToLower(repo.GetName()))
if strings.HasSuffix(gitRepo.Path, relativePath) {
return gitRepo return gitRepo
} }
} }