From 64b57ed6f5a12849f59b8645761fc4ef91eb1d60 Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Wed, 21 Jun 2017 21:06:57 -0400 Subject: [PATCH 1/2] Fix fast-forward PR bug --- models/pull.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/models/pull.go b/models/pull.go index 822822411a4f7..124143bdfd579 100644 --- a/models/pull.go +++ b/models/pull.go @@ -510,6 +510,9 @@ func (pr *PullRequest) getMergeCommit() (*git.Commit, error) { if err != nil { return nil, fmt.Errorf("git rev-list --ancestry-path --merges --reverse: %v %v", stderr, err) + } else if len(mergeCommit) < 40 { + // PR was fast-forwarded, so just use last commit of PR + mergeCommit = commitID[:40] } gitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath()) From e6725e1e33df249705bd3b255ab090ad9562f9d2 Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Wed, 31 May 2017 20:51:24 -0400 Subject: [PATCH 2/2] Don't ignore error in getMergeCommit (#1843) --- models/pull.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/models/pull.go b/models/pull.go index 124143bdfd579..7a79dc3f02387 100644 --- a/models/pull.go +++ b/models/pull.go @@ -499,9 +499,15 @@ func (pr *PullRequest) getMergeCommit() (*git.Commit, error) { return nil, fmt.Errorf("git merge-base --is-ancestor: %v %v", stderr, err) } - // We can ignore this error since we only get here when there's a valid commit in headFile - commitID, _ := ioutil.ReadFile(pr.BaseRepo.RepoPath() + "/" + headFile) - cmd := string(commitID)[:40] + ".." + pr.BaseBranch + commitIDBytes, err := ioutil.ReadFile(pr.BaseRepo.RepoPath() + "/" + headFile) + if err != nil { + return nil, fmt.Errorf("ReadFile(%s): %v", headFile, err) + } + commitID := string(commitIDBytes) + if len(commitID) < 40 { + return nil, fmt.Errorf(`ReadFile(%s): invalid commit-ID "%s"`, headFile, commitID) + } + cmd := commitID[:40] + ".." + pr.BaseBranch // Get the commit from BaseBranch where the pull request got merged mergeCommit, stderr, err := process.GetManager().ExecDirEnv(-1, "", fmt.Sprintf("isMerged (git rev-list --ancestry-path --merges --reverse): %d", pr.BaseRepo.ID),