Refactor various strings (#17784)

Fixes #16478

Co-authored-by: Gusted <williamzijl7@hotmail.com>

Co-authored-by: Gusted <williamzijl7@hotmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
mscherer 2021-12-02 08:28:08 +01:00 committed by GitHub
parent ba57e30f13
commit 34b5436ae1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 46 additions and 33 deletions

View file

@ -403,7 +403,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
for _, result := range results {
// Discard GitHub pull requests, i.e. refs/pull/*
if strings.HasPrefix(result.refName, "refs/pull/") {
if strings.HasPrefix(result.refName, git.PullPrefix) {
continue
}
@ -499,7 +499,7 @@ func checkAndUpdateEmptyRepository(m *models.Mirror, gitRepo *git.Repository, re
}
firstName := ""
for _, result := range results {
if strings.HasPrefix(result.refName, "refs/pull/") {
if strings.HasPrefix(result.refName, git.PullPrefix) {
continue
}
tp, name := git.SplitRefName(result.refName)

View file

@ -421,9 +421,9 @@ func rawMerge(pr *models.PullRequest, doer *user_model.User, mergeStyle models.M
var pushCmd *git.Command
if mergeStyle == models.MergeStyleRebaseUpdate {
// force push the rebase result to head brach
pushCmd = git.NewCommand("push", "-f", "head_repo", stagingBranch+":refs/heads/"+pr.HeadBranch)
pushCmd = git.NewCommand("push", "-f", "head_repo", stagingBranch+":"+git.BranchPrefix+pr.HeadBranch)
} else {
pushCmd = git.NewCommand("push", "origin", baseBranch+":refs/heads/"+pr.BaseBranch)
pushCmd = git.NewCommand("push", "origin", baseBranch+":"+git.BranchPrefix+pr.BaseBranch)
}
// Push back to upstream.

View file

@ -451,8 +451,8 @@ func pushToBaseRepoHelper(pr *models.PullRequest, prefixHeadBranch string) (err
log.Info("Can't push with %s%s", prefixHeadBranch, pr.HeadBranch)
return err
}
log.Info("Retrying to push with refs/heads/%s", pr.HeadBranch)
err = pushToBaseRepoHelper(pr, "refs/heads/")
log.Info("Retrying to push with "+git.BranchPrefix+"%s", pr.HeadBranch)
err = pushToBaseRepoHelper(pr, git.BranchPrefix)
return err
}
log.Error("Unable to push PR head for %s#%d (%-v:%s) due to Error: %v", pr.BaseRepo.FullName(), pr.Index, pr.BaseRepo, gitRefName, err)

View file

@ -152,8 +152,8 @@ func RenameBranch(repo *models.Repository, doer *user_model.User, gitRepo *git.R
return "", err
}
notification.NotifyDeleteRef(doer, repo, "branch", "refs/heads/"+from)
notification.NotifyCreateRef(doer, repo, "branch", "refs/heads/"+to)
notification.NotifyDeleteRef(doer, repo, "branch", git.BranchPrefix+from)
notification.NotifyCreateRef(doer, repo, "branch", git.BranchPrefix+to)
return "", nil
}

View file

@ -266,7 +266,7 @@ func (t *TemporaryUploadRepository) Push(doer *user_model.User, commitHash strin
env := models.PushingEnvironment(doer, t.repo)
if err := git.Push(t.gitRepo.Ctx, t.basePath, git.PushOptions{
Remote: t.repo.RepoPath(),
Branch: strings.TrimSpace(commitHash) + ":refs/heads/" + strings.TrimSpace(branch),
Branch: strings.TrimSpace(commitHash) + ":" + git.BranchPrefix + strings.TrimSpace(branch),
Env: env,
}); err != nil {
if git.IsErrPushOutOfDate(err) {