From 25ec20d5251511ebd0b9e6b963e189b860c39704 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 3 Nov 2015 17:25:39 -0500 Subject: #1838 update merge base before generate new patch --- modules/git/repo_pull.go | 50 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) (limited to 'modules/git/repo_pull.go') diff --git a/modules/git/repo_pull.go b/modules/git/repo_pull.go index a9cc33a1..16b9536f 100644 --- a/modules/git/repo_pull.go +++ b/modules/git/repo_pull.go @@ -20,31 +20,55 @@ type PullRequestInfo struct { NumFiles int } +// GetMergeBase checks and returns merge base of two branches. +func (repo *Repository) GetMergeBase(remoteBranch, headBranch string) (string, error) { + // Get merge base commit. + stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "merge-base", remoteBranch, headBranch) + if err != nil { + return "", fmt.Errorf("get merge base: %v", concatenateError(err, stderr)) + } + return strings.TrimSpace(stdout), nil +} + +// AddRemote adds a remote to repository. +func (repo *Repository) AddRemote(name, path string) error { + _, stderr, err := com.ExecCmdDir(repo.Path, "git", "remote", "add", "-f", name, path) + if err != nil { + return fmt.Errorf("add remote(%s - %s): %v", name, path, concatenateError(err, stderr)) + } + return nil +} + +// RemoveRemote removes a remote from repository. +func (repo *Repository) RemoveRemote(name string) error { + _, stderr, err := com.ExecCmdDir(repo.Path, "git", "remote", "remove", name) + if err != nil { + return fmt.Errorf("remove remote(%s): %v", name, concatenateError(err, stderr)) + } + return nil +} + // GetPullRequestInfo generates and returns pull request information // between base and head branches of repositories. -func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch string) (*PullRequestInfo, error) { +func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch string) (_ *PullRequestInfo, err error) { // Add a temporary remote. tmpRemote := com.ToStr(time.Now().UnixNano()) - _, stderr, err := com.ExecCmdDir(repo.Path, "git", "remote", "add", "-f", tmpRemote, basePath) - if err != nil { - return nil, fmt.Errorf("add base as remote: %v", concatenateError(err, stderr)) + if err = repo.AddRemote(tmpRemote, basePath); err != nil { + return nil, fmt.Errorf("AddRemote: %v", err) } defer func() { - com.ExecCmdDir(repo.Path, "git", "remote", "remove", tmpRemote) + repo.RemoveRemote(tmpRemote) }() - prInfo := new(PullRequestInfo) - - var stdout string remoteBranch := "remotes/" + tmpRemote + "/" + baseBranch - // Get merge base commit. - stdout, stderr, err = com.ExecCmdDir(repo.Path, "git", "merge-base", remoteBranch, headBranch) + + prInfo := new(PullRequestInfo) + prInfo.MergeBase, err = repo.GetMergeBase(remoteBranch, headBranch) if err != nil { - return nil, fmt.Errorf("get merge base: %v", concatenateError(err, stderr)) + return nil, fmt.Errorf("GetMergeBase: %v", err) } - prInfo.MergeBase = strings.TrimSpace(stdout) - stdout, stderr, err = com.ExecCmdDir(repo.Path, "git", "log", prInfo.MergeBase+"..."+headBranch, prettyLogFormat) + stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "log", prInfo.MergeBase+"..."+headBranch, prettyLogFormat) if err != nil { return nil, fmt.Errorf("list diff logs: %v", concatenateError(err, stderr)) } -- cgit v1.2.3 From e06558e2083e6281500cc1c91ac54425b91390fe Mon Sep 17 00:00:00 2001 From: Unknwon Date: Mon, 16 Nov 2015 21:18:04 -0500 Subject: #1922 Pull request fail to merge with BIN --- README.md | 2 +- gogs.go | 2 +- models/pull.go | 1 + modules/git/repo_pull.go | 2 +- templates/.VERSION | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) (limited to 'modules/git/repo_pull.go') diff --git a/README.md b/README.md index 1e363ded..c649a382 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra ![](public/img/gogs-large-resize.png) -##### Current version: 0.7.13 Beta +##### Current version: 0.7.14 Beta diff --git a/gogs.go b/gogs.go index f8a39f3f..80f780e8 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.7.13.1116 Beta" +const APP_VER = "0.7.14.1116 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/pull.go b/models/pull.go index 094cb9b2..5c7d4a3f 100644 --- a/models/pull.go +++ b/models/pull.go @@ -260,6 +260,7 @@ func (pr *PullRequest) testPatch() (err error) { for i := range patchConflicts { if strings.Contains(stderr, patchConflicts[i]) { log.Trace("PullRequest[%d].testPatch(apply): has conflit", pr.ID) + fmt.Println(stderr) pr.Status = PULL_REQUEST_STATUS_CONFLICT return nil } diff --git a/modules/git/repo_pull.go b/modules/git/repo_pull.go index 16b9536f..f9ea7100 100644 --- a/modules/git/repo_pull.go +++ b/modules/git/repo_pull.go @@ -89,7 +89,7 @@ func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch stri // GetPatch generates and returns patch data between given branches. func (repo *Repository) GetPatch(mergeBase, headBranch string) ([]byte, error) { - stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "diff", "-p", mergeBase, headBranch) + stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "diff", "-p", "--binary", mergeBase, headBranch) if err != nil { return nil, concatenateError(err, string(stderr)) } diff --git a/templates/.VERSION b/templates/.VERSION index 87a10ba3..b0072b13 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.7.13.1116 Beta \ No newline at end of file +0.7.14.1116 Beta \ No newline at end of file -- cgit v1.2.3