summaryrefslogtreecommitdiffstats
path: root/models/pull.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-11-03 17:25:39 -0500
committerUnknwon <u@gogs.io>2015-11-03 17:25:39 -0500
commit25ec20d5251511ebd0b9e6b963e189b860c39704 (patch)
tree7c771f0a8403fd62811fdadcbe8d118d89edec20 /models/pull.go
parent8e262f3ec4c961487fe56b6b64573a2f9b928c70 (diff)
downloadgitea-25ec20d5251511ebd0b9e6b963e189b860c39704.tar.gz
gitea-25ec20d5251511ebd0b9e6b963e189b860c39704.zip
#1838 update merge base before generate new patch
Diffstat (limited to 'models/pull.go')
-rw-r--r--models/pull.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/models/pull.go b/models/pull.go
index 0300c083d7..56af5f828d 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -385,16 +385,18 @@ func (pr *PullRequest) UpdateCols(cols ...string) error {
var PullRequestQueue = NewUniqueQueue(setting.Repository.PullRequestQueueLength)
// UpdatePatch generates and saves a new patch.
-func (pr *PullRequest) UpdatePatch() error {
- if err := pr.GetHeadRepo(); err != nil {
+func (pr *PullRequest) UpdatePatch() (err error) {
+ if err = pr.GetHeadRepo(); err != nil {
return fmt.Errorf("GetHeadRepo: %v", err)
} else if pr.HeadRepo == nil {
log.Trace("PullRequest[%d].UpdatePatch: ignored cruppted data", pr.ID)
return nil
}
- if err := pr.GetBaseRepo(); err != nil {
+ if err = pr.GetBaseRepo(); err != nil {
return fmt.Errorf("GetBaseRepo: %v", err)
+ } else if err = pr.BaseRepo.GetOwner(); err != nil {
+ return fmt.Errorf("GetOwner: %v", err)
}
headRepoPath, err := pr.HeadRepo.RepoPath()
@@ -407,6 +409,22 @@ func (pr *PullRequest) UpdatePatch() error {
return fmt.Errorf("OpenRepository: %v", err)
}
+ // Add a temporary remote.
+ tmpRemote := com.ToStr(time.Now().UnixNano())
+ if err = headGitRepo.AddRemote(tmpRemote, RepoPath(pr.BaseRepo.Owner.Name, pr.BaseRepo.Name)); err != nil {
+ return fmt.Errorf("AddRemote: %v", err)
+ }
+ defer func() {
+ headGitRepo.RemoveRemote(tmpRemote)
+ }()
+ remoteBranch := "remotes/" + tmpRemote + "/" + pr.BaseBranch
+ pr.MergeBase, err = headGitRepo.GetMergeBase(remoteBranch, pr.HeadBranch)
+ if err != nil {
+ return fmt.Errorf("GetMergeBase: %v", err)
+ } else if err = pr.Update(); err != nil {
+ return fmt.Errorf("Update: %v", err)
+ }
+
patch, err := headGitRepo.GetPatch(pr.MergeBase, pr.HeadBranch)
if err != nil {
return fmt.Errorf("GetPatch: %v", err)