Browse Source

models/pull: fix error on merge pull requests to non-default branch (#5138)

Unknwon 7 years ago
parent
commit
8b66c433c5
3 changed files with 5 additions and 11 deletions
  1. 1 1
      gogs.go
  2. 3 9
      models/pull.go
  3. 1 1
      templates/.VERSION

+ 1 - 1
gogs.go

@@ -16,7 +16,7 @@ import (
 	"github.com/gogits/gogs/pkg/setting"
 )
 
-const APP_VER = "0.11.43.0330"
+const APP_VER = "0.11.44.0409"
 
 func init() {
 	setting.AppVer = APP_VER

+ 3 - 9
models/pull.go

@@ -221,11 +221,12 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
 	os.MkdirAll(path.Dir(tmpBasePath), os.ModePerm)
 	defer os.RemoveAll(path.Dir(tmpBasePath))
 
-	// Clone the base repository to the defined temporary directory.
+	// Clone the base repository to the defined temporary directory,
+	// and checks out to base branch directly.
 	var stderr string
 	if _, stderr, err = process.ExecTimeout(5*time.Minute,
 		fmt.Sprintf("PullRequest.Merge (git clone): %s", tmpBasePath),
-		"git", "clone", baseGitRepo.Path, tmpBasePath); err != nil {
+		"git", "clone", "-b", pr.BaseBranch, baseGitRepo.Path, tmpBasePath); err != nil {
 		return fmt.Errorf("git clone: %s", stderr)
 	}
 
@@ -253,13 +254,6 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
 	switch mergeStyle {
 	case MERGE_STYLE_REGULAR: // Create merge commit
 
-		// Check out the base branch to be operated on.
-		if _, stderr, err = process.ExecDir(-1, tmpBasePath,
-			fmt.Sprintf("PullRequest.Merge (git checkout): %s", tmpBasePath),
-			"git", "checkout", pr.BaseBranch); err != nil {
-			return fmt.Errorf("git checkout '%s': %s", pr.BaseBranch, stderr)
-		}
-
 		// Merge changes from head branch.
 		if _, stderr, err = process.ExecDir(-1, tmpBasePath,
 			fmt.Sprintf("PullRequest.Merge (git merge --no-ff --no-commit): %s", tmpBasePath),

+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
-0.11.43.0330
+0.11.44.0409