diff options
author | Unknwon <u@gogs.io> | 2016-02-19 22:16:26 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-02-19 22:16:26 -0500 |
commit | b7f3d94cd048cbad6bc406bcbd79b490ccd416a9 (patch) | |
tree | df26c86962664b4dbb718af7359fc690b142ac5d /models/pull.go | |
parent | f6c98465c79b87f717e7687af16939d3305461f5 (diff) | |
download | gitea-b7f3d94cd048cbad6bc406bcbd79b490ccd416a9.tar.gz gitea-b7f3d94cd048cbad6bc406bcbd79b490ccd416a9.zip |
Minor fix for #2524
Diffstat (limited to 'models/pull.go')
-rw-r--r-- | models/pull.go | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/models/pull.go b/models/pull.go index 67f103e8d5..bf16d98fa7 100644 --- a/models/pull.go +++ b/models/pull.go @@ -20,7 +20,6 @@ import ( "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/process" "github.com/gogits/gogs/modules/setting" - "strconv" ) type PullRequestType int @@ -483,35 +482,28 @@ func (pr *PullRequest) UpdatePatch() (err error) { return nil } +// PushToBaseRepo pushes commits from branches of head repository to +// corresponding branches of base repository. +// FIXME: could fail after user force push head repo, should we always force push here? +// FIXME: Only push branches that are actually updates? func (pr *PullRequest) PushToBaseRepo() (err error) { - log.Trace("PushToBase[%d]: pushing commits to base repo refs/pull/%d/head", pr.ID, pr.ID) + log.Trace("PushToBaseRepo[%[1]d]: pushing commits to base repo 'refs/pull/%[1]d/head'", pr.ID) - branch := pr.HeadBranch - - if err = pr.BaseRepo.GetOwner(); err != nil { - return fmt.Errorf("Could not get base repo owner data: %v", err) - } else if err = pr.HeadRepo.GetOwner(); err != nil { - return fmt.Errorf("Could not get head repo owner data: %v", err) - } - - headRepoPath := RepoPath(pr.HeadRepo.Owner.Name, pr.HeadRepo.Name) - - prIdStr := strconv.FormatInt(pr.ID, 10) - tmpRemoteName := "tmp-pull-" + branch + "-" + prIdStr - repo, err := git.OpenRepository(headRepoPath) + headRepoPath := pr.HeadRepo.RepoPath() + headGitRepo, err := git.OpenRepository(headRepoPath) if err != nil { - return fmt.Errorf("Unable to open head repository: %v", err) + return fmt.Errorf("OpenRepository: %v", err) } - if err = repo.AddRemote(tmpRemoteName, RepoPath(pr.BaseRepo.Owner.Name, pr.BaseRepo.Name), false); err != nil { - return fmt.Errorf("Unable to add remote to head repository: %v", err) + tmpRemoteName := fmt.Sprintf("tmp-pull-%d", pr.ID) + if err = headGitRepo.AddRemote(tmpRemoteName, pr.BaseRepo.RepoPath(), false); err != nil { + return fmt.Errorf("headGitRepo.AddRemote: %v", err) } // Make sure to remove the remote even if the push fails - defer repo.RemoveRemote(tmpRemoteName) + defer headGitRepo.RemoveRemote(tmpRemoteName) - pushRef := branch+":"+"refs/pull/"+prIdStr+"/head" - if err = git.Push(headRepoPath, tmpRemoteName, pushRef); err != nil { - return fmt.Errorf("Error pushing: %v", err) + if err = git.Push(headRepoPath, tmpRemoteName, fmt.Sprintf("%s:refs/pull/%d/head", pr.HeadBranch, pr.Index)); err != nil { + return fmt.Errorf("Push: %v", err) } return nil |