瀏覽代碼

#1597 fix pull request remote head can't update with force push

Unknwon 9 年之前
父節點
當前提交
e2d370f0da
共有 2 個文件被更改,包括 7 次插入2 次删除
  1. 1 1
      models/issue.go
  2. 6 1
      models/pull.go

+ 1 - 1
models/issue.go

@@ -301,7 +301,7 @@ func newIssue(e *xorm.Session, repo *Repository, issue *Issue, labelIDs []int64,
 	// So we have to get all needed labels first.
 	labels := make([]*Label, 0, len(labelIDs))
 	if err = e.In("id", labelIDs).Find(&labels); err != nil {
-		return fmt.Errorf("Find all labels: %v", err)
+		return fmt.Errorf("find all labels: %v", err)
 	}
 
 	for _, label := range labels {

+ 6 - 1
models/pull.go

@@ -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)
 	}