From 0973c036019c955172ebce99d58eede2e9ac55ca Mon Sep 17 00:00:00 2001 From: zeripath Date: Fri, 12 Jun 2020 00:49:47 +0100 Subject: Handle more pathological branch and tag names (#11843) * Handle more pathological branch and tag names Signed-off-by: Andrew Thornton * Fix failing test Signed-off-by: Andrew Thornton Co-authored-by: techknowlogick --- services/pull/pull.go | 2 +- services/pull/temp_repo.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'services') diff --git a/services/pull/pull.go b/services/pull/pull.go index e8912e47c6..f7a187848a 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -66,7 +66,7 @@ func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int6 defer baseGitRepo.Close() compareInfo, err := baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), - pr.BaseBranch, pr.GetGitRefName()) + git.BranchPrefix+pr.BaseBranch, pr.GetGitRefName()) if err != nil { return err } diff --git a/services/pull/temp_repo.go b/services/pull/temp_repo.go index 91f48d0626..45cd10b65b 100644 --- a/services/pull/temp_repo.go +++ b/services/pull/temp_repo.go @@ -100,7 +100,7 @@ func createTemporaryRepo(pr *models.PullRequest) (string, error) { outbuf.Reset() errbuf.Reset() - if err := git.NewCommand("fetch", "origin", "--no-tags", pr.BaseBranch+":"+baseBranch, pr.BaseBranch+":original_"+baseBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil { + if err := git.NewCommand("fetch", "origin", "--no-tags", "--", pr.BaseBranch+":"+baseBranch, pr.BaseBranch+":original_"+baseBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil { log.Error("Unable to fetch origin base branch [%s:%s -> base, original_base in %s]: %v:\n%s\n%s", pr.BaseRepo.FullName(), pr.BaseBranch, tmpBasePath, err, outbuf.String(), errbuf.String()) if err := models.RemoveTemporaryPath(tmpBasePath); err != nil { log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err) @@ -140,7 +140,7 @@ func createTemporaryRepo(pr *models.PullRequest) (string, error) { trackingBranch := "tracking" // Fetch head branch - if err := git.NewCommand("fetch", "--no-tags", remoteRepoName, pr.HeadBranch+":"+trackingBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil { + if err := git.NewCommand("fetch", "--no-tags", remoteRepoName, git.BranchPrefix+pr.HeadBranch+":"+trackingBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil { log.Error("Unable to fetch head_repo head branch [%s:%s -> tracking in %s]: %v:\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, tmpBasePath, err, outbuf.String(), errbuf.String()) if err := models.RemoveTemporaryPath(tmpBasePath); err != nil { log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err) -- cgit v1.2.3