aboutsummaryrefslogtreecommitdiffstats
path: root/models/pull.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/pull.go')
-rw-r--r--models/pull.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/models/pull.go b/models/pull.go
index 276dc1bcfd..8103d71ea1 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -487,7 +487,7 @@ func (pr *PullRequest) UpdatePatch() (err error) {
// 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("PushToBaseRepo[%[1]d]: pushing commits to base repo 'refs/pull/%[1]d/head'", pr.ID)
+ log.Trace("PushToBaseRepo[%d]: pushing commits to base repo 'refs/pull/%d/head'", pr.BaseRepoID, pr.Index)
headRepoPath := pr.HeadRepo.RepoPath()
headGitRepo, err := git.OpenRepository(headRepoPath)
@@ -502,7 +502,12 @@ func (pr *PullRequest) PushToBaseRepo() (err error) {
// Make sure to remove the remote even if the push fails
defer headGitRepo.RemoveRemote(tmpRemoteName)
- if err = git.Push(headRepoPath, tmpRemoteName, fmt.Sprintf("%s:refs/pull/%d/head", pr.HeadBranch, pr.Index)); err != nil {
+ headFile := fmt.Sprintf("refs/pull/%d/head", pr.Index)
+
+ // Remove head in case there is a conflict.
+ os.Remove(path.Join(pr.BaseRepo.RepoPath(), headFile))
+
+ if err = git.Push(headRepoPath, tmpRemoteName, fmt.Sprintf("%s:%s", pr.HeadBranch, headFile)); err != nil {
return fmt.Errorf("Push: %v", err)
}