Skip to content

Handle branch name with prefix in GitHub migration #20357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Nov 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement the same method for gogit
  • Loading branch information
harryzcy committed Jul 14, 2022
commit 6e1ee49c77c236bc376dced5fb2c71ead6a8f7a6
17 changes: 17 additions & 0 deletions modules/git/repo_branch_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ func (repo *Repository) IsBranchExist(name string) bool {
return reference.Type() != plumbing.InvalidReference
}

// ResolveBranch resolves an ambiguous branch name to its explicit name, and if the branch exists.
// i.e. "main" -> "refs/heads/main"
func (repo *Repository) ResolveBranch(name string) (string, bool) {
if name == "" {
return "", false
}

if repo.IsReferenceExist(name) {
return name, true
}
if repo.IsReferenceExist(BranchPrefix + name) {
return BranchPrefix + name, true
}

return "", false
}

// GetBranches returns branches from the repository, skipping skip initial branches and
// returning at most limit branches, or all branches if limit is 0.
func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error) {
Expand Down