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
Show file tree
Hide file tree
Changes from 2 commits
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
5 changes: 4 additions & 1 deletion modules/git/repo_branch_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ func (repo *Repository) IsBranchExist(name string) bool {
return false
}

return repo.IsReferenceExist(BranchPrefix + name)
if !strings.HasPrefix(name, BranchPrefix) {
name = BranchPrefix + name
}
return repo.IsReferenceExist(name)
}

// GetBranchNames returns branches from the repository, skipping skip initial branches and
Expand Down
10 changes: 8 additions & 2 deletions modules/git/repo_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ import (

// GetBranchCommitID returns last commit ID string of given branch.
func (repo *Repository) GetBranchCommitID(name string) (string, error) {
return repo.GetRefCommitID(BranchPrefix + name)
if !strings.HasPrefix(name, BranchPrefix) {
name = BranchPrefix + name
}
return repo.GetRefCommitID(name)
}

// GetTagCommitID returns last commit ID string of given tag.
func (repo *Repository) GetTagCommitID(name string) (string, error) {
return repo.GetRefCommitID(TagPrefix + name)
if !strings.HasPrefix(name, TagPrefix) {
name = TagPrefix + name
}
return repo.GetRefCommitID(name)
}

// GetCommit returns commit object of by ID string.
Expand Down
3 changes: 2 additions & 1 deletion routers/web/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
Expand All @@ -35,7 +36,7 @@ const (
// calReleaseNumCommitsBehind calculates given release has how many commits behind release target.
func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *models.Release, countCache map[string]int64) error {
// Fast return if release target is same as default branch.
if repoCtx.BranchName == release.Target {
if repoCtx.BranchName == strings.TrimPrefix(release.Target, git.BranchPrefix) {
release.NumCommitsBehind = repoCtx.CommitsCount - release.NumCommits
return nil
}
Expand Down