1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
From d90735d2e8ddfe02794a772ae07666aa4ebc105e Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Thu, 2 Apr 2020 22:46:50 +0200
Subject: [PATCH] Fix rebase conflict detection in git 2.26
Git changed the technique used in rebase from
simple apply-patches to use merge. This breaks
our conflict detection code.
created by: Andrew Thornton <art27@cantab.net>
---
services/pull/merge.go | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/services/pull/merge.go b/services/pull/merge.go
index f9d9a27c9..b71784f00 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -211,17 +211,34 @@ func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repositor
if err := git.NewCommand("rebase", baseBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
// Rebase will leave a REBASE_HEAD file in .git if there is a conflict
if _, statErr := os.Stat(filepath.Join(tmpBasePath, ".git", "REBASE_HEAD")); statErr == nil {
- // The original commit SHA1 that is failing will be in .git/rebase-apply/original-commit
- commitShaBytes, readErr := ioutil.ReadFile(filepath.Join(tmpBasePath, ".git", "rebase-apply", "original-commit"))
- if readErr != nil {
- // Abandon this attempt to handle the error
+ var commitSha string
+ ok := false
+ failingCommitPaths := []string{
+ filepath.Join(tmpBasePath, ".git", "rebase-apply", "original-commit"), // Git < 2.26
+ filepath.Join(tmpBasePath, ".git", "rebase-merge", "stopped-sha"), // Git >= 2.26
+ }
+ for _, failingCommitPath := range failingCommitPaths {
+ if _, statErr := os.Stat(filepath.Join(failingCommitPath)); statErr == nil {
+ commitShaBytes, readErr := ioutil.ReadFile(filepath.Join(failingCommitPath))
+ if readErr != nil {
+ // Abandon this attempt to handle the error
+ log.Error("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
+ return fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
+ }
+ commitSha = strings.TrimSpace(string(commitShaBytes))
+ ok = true
+ break
+ }
+ }
+ if !ok {
+ log.Error("Unable to determine failing commit sha for this rebase message. Cannot cast as models.ErrRebaseConflicts.")
log.Error("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
return fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
}
- log.Debug("RebaseConflict at %s [%s:%s -> %s:%s]: %v\n%s\n%s", strings.TrimSpace(string(commitShaBytes)), pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
+ log.Debug("RebaseConflict at %s [%s:%s -> %s:%s]: %v\n%s\n%s", commitSha, pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
return models.ErrRebaseConflicts{
Style: mergeStyle,
- CommitSHA: strings.TrimSpace(string(commitShaBytes)),
+ CommitSHA: commitSha,
StdOut: outbuf.String(),
StdErr: errbuf.String(),
Err: err,
--
2.26.0
|