mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-18 11:59:27 +00:00
#1838 update merge base before generate new patch
This commit is contained in:
parent
8e262f3ec4
commit
25ec20d525
|
@ -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.6.22 Beta
|
||||
##### Current version: 0.6.23 Beta
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const APP_VER = "0.6.22.1103 Beta"
|
||||
const APP_VER = "0.6.23.1103 Beta"
|
||||
|
||||
func init() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
|
|
@ -97,7 +97,7 @@ func ParsePatch(pid int64, maxlines int, cmd *exec.Cmd, reader io.Reader) (*Diff
|
|||
var i int
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
// fmt.Println(i, line)
|
||||
|
||||
if strings.HasPrefix(line, "+++ ") || strings.HasPrefix(line, "--- ") {
|
||||
continue
|
||||
}
|
||||
|
@ -180,8 +180,6 @@ func ParsePatch(pid int64, maxlines int, cmd *exec.Cmd, reader io.Reader) (*Diff
|
|||
b = b[1 : len(b)-1]
|
||||
}
|
||||
|
||||
fmt.Println(a, b)
|
||||
|
||||
curFile = &DiffFile{
|
||||
Name: a,
|
||||
Index: len(diff.Files) + 1,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get merge base: %v", concatenateError(err, stderr))
|
||||
}
|
||||
prInfo.MergeBase = strings.TrimSpace(stdout)
|
||||
|
||||
stdout, stderr, err = com.ExecCmdDir(repo.Path, "git", "log", prInfo.MergeBase+"..."+headBranch, prettyLogFormat)
|
||||
prInfo := new(PullRequestInfo)
|
||||
prInfo.MergeBase, err = repo.GetMergeBase(remoteBranch, headBranch)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetMergeBase: %v", err)
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.6.22.1103 Beta
|
||||
0.6.23.1103 Beta
|
Loading…
Reference in a new issue