From 76afefc4a1afb0c8d4ddc24788756b19fb1adfea Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 6 Apr 2021 21:28:36 +0100 Subject: [PATCH 1/6] Improve TestPatch to make it much quicker when there are no conflicts and large files Signed-off-by: Andrew Thornton --- services/pull/patch.go | 222 ++++++++++++++++++++++++----------------- 1 file changed, 129 insertions(+), 93 deletions(-) diff --git a/services/pull/patch.go b/services/pull/patch.go index 72b459bf2cb3d..2b8051943f81d 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -10,14 +10,12 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "strings" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/util" "github.com/gobwas/glob" ) @@ -99,31 +97,65 @@ func TestPatch(pr *models.PullRequest) error { } func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath string) (bool, error) { - // 1. Create a plain patch from head to base - tmpPatchFile, err := ioutil.TempFile("", "patch") + // 1. preset the pr.Status as checking (this is not saved at present) + pr.Status = models.PullRequestStatusChecking + + // 2. Now get the pull request configuration to check if we need to ignore whitespace + prUnit, err := pr.BaseRepo.GetUnit(models.UnitTypePullRequests) if err != nil { - log.Error("Unable to create temporary patch file! Error: %v", err) - return false, fmt.Errorf("Unable to create temporary patch file! Error: %v", err) + return false, err + } + prConfig := prUnit.PullRequestsConfig() + + // 3. Read the base branch in to the index of the temporary repository + if _, err := git.NewCommand("read-tree", "base").RunInDir(tmpBasePath); err != nil { + return false, fmt.Errorf("git read-tree %s: %v", pr.BaseBranch, err) } + + // 4. Now use read-tree -m to shortcut if there are no conflicts + if _, err := git.NewCommand("read-tree", "-m", pr.MergeBase, "base", "tracking").RunInDir(tmpBasePath); err != nil { + return false, fmt.Errorf("git read-tree %s: %v", pr.BaseBranch, err) + } + + // 4b. Now check git status to see if there are any conflicted files + statusReader, statusWriter := io.Pipe() defer func() { - _ = util.Remove(tmpPatchFile.Name()) + _ = statusReader.Close() + _ = statusWriter.Close() }() - if err := gitRepo.GetDiff(pr.MergeBase, "tracking", tmpPatchFile); err != nil { - tmpPatchFile.Close() - log.Error("Unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) - return false, fmt.Errorf("Unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) - } - stat, err := tmpPatchFile.Stat() - if err != nil { - tmpPatchFile.Close() - return false, fmt.Errorf("Unable to stat patch file: %v", err) + go func() { + stderr := &strings.Builder{} + if err := git.NewCommand("status", "--porcelain", "-z").RunInDirPipeline(tmpBasePath, statusWriter, stderr); err != nil { + _ = statusWriter.CloseWithError(git.ConcatenateError(err, stderr.String())) + } else { + _ = statusWriter.Close() + } + }() + + conflictFiles := []string{} + numFiles := 0 + + bufReader := bufio.NewReader(statusReader) +loop: + for { + line, err := bufReader.ReadString('\000') + if err != nil { + break loop + } + numFiles++ + if len(line) < 3 || line[3] != ' ' { + continue + } + // Conflicted statuses + if !strings.Contains("DD AU UD UA DU AA UU ", line[:3]) { + continue + } + conflictFiles = append(conflictFiles, line[3:]) } - patchPath := tmpPatchFile.Name() - tmpPatchFile.Close() - // 1a. if the size of that patch is 0 - there can be no conflicts! - if stat.Size() == 0 { + // 4c. If there are no files changed this is an empty patch + if numFiles == 0 { log.Debug("PullRequest[%d]: Patch is empty - ignoring", pr.ID) pr.Status = models.PullRequestStatusEmpty pr.ConflictedFiles = []string{} @@ -131,33 +163,44 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath return false, nil } - log.Trace("PullRequest[%d].testPatch (patchPath): %s", pr.ID, patchPath) + // 4d. If there are no potentially conflicted files stop + if len(conflictFiles) == 0 { + pr.ConflictedFiles = []string{} + return false, nil + } - // 2. preset the pr.Status as checking (this is not save at present) - pr.Status = models.PullRequestStatusChecking + // 5a. Prepare the diff + diffReader, diffWriter := io.Pipe() + defer func() { + _ = diffReader.Close() + _ = diffWriter.Close() + }() - // 3. Read the base branch in to the index of the temporary repository - _, err = git.NewCommand("read-tree", "base").RunInDir(tmpBasePath) - if err != nil { - return false, fmt.Errorf("git read-tree %s: %v", pr.BaseBranch, err) - } + args := make([]string, 0, len(conflictFiles)+5) + args = append(args, "diff", "-p", pr.MergeBase, "tracking", "--") + args = append(args, conflictFiles...) - // 4. Now get the pull request configuration to check if we need to ignore whitespace - prUnit, err := pr.BaseRepo.GetUnit(models.UnitTypePullRequests) - if err != nil { - return false, err - } - prConfig := prUnit.PullRequestsConfig() + // 5b. Create a plain patch from head to base + go func() { + if err := git.NewCommand(args...).RunInDirPipeline(tmpBasePath, diffWriter, nil); err != nil { + log.Error("Unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) + _ = diffWriter.CloseWithError(err) + return + } + _ = diffWriter.Close() + }() + + args = args[:0] - // 5. Prepare the arguments to apply the patch against the index - args := []string{"apply", "--check", "--cached"} + // 5c. Prepare the arguments to apply the patch against the index + args = append(args, "apply", "--check", "--cached") if prConfig.IgnoreWhitespaceConflicts { args = append(args, "--ignore-whitespace") } - args = append(args, patchPath) + args = append(args, "-") pr.ConflictedFiles = make([]string, 0, 5) - // 6. Prep the pipe: + // 5d. Prep the pipe: // - Here we could do the equivalent of: // `git apply --check --cached patch_file > conflicts` // Then iterate through the conflicts. However, that means storing all the conflicts @@ -165,72 +208,65 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath // - alternatively we can do the equivalent of: // `git apply --check ... | grep ...` // meaning we don't store all of the conflicts unnecessarily. - stderrReader, stderrWriter, err := os.Pipe() - if err != nil { - log.Error("Unable to open stderr pipe: %v", err) - return false, fmt.Errorf("Unable to open stderr pipe: %v", err) - } + stderrReader, stderrWriter := io.Pipe() defer func() { _ = stderrReader.Close() _ = stderrWriter.Close() }() - // 7. Run the check command + // 5e. Run the apply --check command conflict := false - err = git.NewCommand(args...). - RunInDirTimeoutEnvFullPipelineFunc( - nil, -1, tmpBasePath, - nil, stderrWriter, nil, - func(ctx context.Context, cancel context.CancelFunc) error { - // Close the writer end of the pipe to begin processing - _ = stderrWriter.Close() - defer func() { - // Close the reader on return to terminate the git command if necessary - _ = stderrReader.Close() - }() - - const prefix = "error: patch failed:" - const errorPrefix = "error: " - - conflictMap := map[string]bool{} - - // Now scan the output from the command - scanner := bufio.NewScanner(stderrReader) - for scanner.Scan() { - line := scanner.Text() - if strings.HasPrefix(line, prefix) { - conflict = true - filepath := strings.TrimSpace(strings.Split(line[len(prefix):], ":")[0]) + go func() { + if err := git.NewCommand(args...).RunInDirTimeoutEnvFullPipeline(nil, -1, tmpBasePath, nil, stderrWriter, diffReader); err != nil { + _ = stderrWriter.CloseWithError(err) + return + } + _ = stderrWriter.Close() + }() + const empty = "error: unrecognised input" + + const prefix = "error: patch failed:" + const errorPrefix = "error: " + + conflictMap := map[string]bool{} + + // 5f. Now scan the output from the command + scanner := bufio.NewScanner(stderrReader) + for scanner.Scan() { + line := scanner.Text() + if strings.EqualFold(line, empty) && !conflict { + // ignore + } else if strings.HasPrefix(line, prefix) { + conflict = true + filepath := strings.TrimSpace(strings.Split(line[len(prefix):], ":")[0]) + conflictMap[filepath] = true + } else if strings.HasPrefix(line, errorPrefix) { + conflict = true + for _, suffix := range patchErrorSuffices { + if strings.HasSuffix(line, suffix) { + filepath := strings.TrimSpace(strings.TrimSuffix(line[len(errorPrefix):], suffix)) + if filepath != "" { conflictMap[filepath] = true - } else if strings.HasPrefix(line, errorPrefix) { - conflict = true - for _, suffix := range patchErrorSuffices { - if strings.HasSuffix(line, suffix) { - filepath := strings.TrimSpace(strings.TrimSuffix(line[len(errorPrefix):], suffix)) - if filepath != "" { - conflictMap[filepath] = true - } - break - } - } - } - // only list 10 conflicted files - if len(conflictMap) >= 10 { - break - } - } - - if len(conflictMap) > 0 { - pr.ConflictedFiles = make([]string, 0, len(conflictMap)) - for key := range conflictMap { - pr.ConflictedFiles = append(pr.ConflictedFiles, key) } + break } + } + } + // only list 10 conflicted files + if len(conflictMap) >= 10 { + break + } + } + err = scanner.Err() - return nil - }) + if len(conflictMap) > 0 { + pr.ConflictedFiles = make([]string, 0, len(conflictMap)) + for key := range conflictMap { + pr.ConflictedFiles = append(pr.ConflictedFiles, key) + } + } - // 8. If there is a conflict the `git apply` command will return a non-zero error code - so there will be a positive error. + // 6. If there is a conflict the `git apply` command will return a non-zero error code - so there will be a positive error. if err != nil { if conflict { pr.Status = models.PullRequestStatusConflict From b6901a4e5bebeb2a7258a6d8b7f063e6b64d8741 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 6 Apr 2021 21:48:59 +0100 Subject: [PATCH 2/6] no lint I actually meant what I wrote Signed-off-by: Andrew Thornton --- services/pull/patch.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/pull/patch.go b/services/pull/patch.go index 2b8051943f81d..ced047c2d6f44 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -96,6 +96,8 @@ func TestPatch(pr *models.PullRequest) error { return nil } +const conflictStatus = "DD AU UD UA DU AA UU " + func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath string) (bool, error) { // 1. preset the pr.Status as checking (this is not saved at present) pr.Status = models.PullRequestStatusChecking @@ -148,7 +150,7 @@ loop: continue } // Conflicted statuses - if !strings.Contains("DD AU UD UA DU AA UU ", line[:3]) { + if !strings.Contains(conflictStatus, line[:3]) { continue } conflictFiles = append(conflictFiles, line[3:]) From a9c4146674ba46fa7a6eb14937f6bd84be659f50 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Wed, 7 Apr 2021 08:47:03 +0100 Subject: [PATCH 3/6] Fix empty merge detection Signed-off-by: Andrew Thornton --- services/pull/patch.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/pull/patch.go b/services/pull/patch.go index ced047c2d6f44..78e5eaf8ea155 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -145,10 +145,10 @@ loop: if err != nil { break loop } - numFiles++ - if len(line) < 3 || line[3] != ' ' { + if len(line) < 3 || line[3] != ' ' || line[0] == ' ' { continue } + numFiles++ // Conflicted statuses if !strings.Contains(conflictStatus, line[:3]) { continue From 702768d0991e916c024dc777426e9231da5a0625 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Wed, 7 Apr 2021 15:58:29 +0100 Subject: [PATCH 4/6] use aggressive and fix more issues Signed-off-by: Andrew Thornton --- services/pull/patch.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/services/pull/patch.go b/services/pull/patch.go index 78e5eaf8ea155..103303841ab11 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -115,7 +115,7 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath } // 4. Now use read-tree -m to shortcut if there are no conflicts - if _, err := git.NewCommand("read-tree", "-m", pr.MergeBase, "base", "tracking").RunInDir(tmpBasePath); err != nil { + if _, err := git.NewCommand("read-tree", "-m", "--aggressive", pr.MergeBase, "base", "tracking").RunInDir(tmpBasePath); err != nil { return false, fmt.Errorf("git read-tree %s: %v", pr.BaseBranch, err) } @@ -145,15 +145,23 @@ loop: if err != nil { break loop } - if len(line) < 3 || line[3] != ' ' || line[0] == ' ' { + if len(line) < 3 { continue } - numFiles++ - // Conflicted statuses - if !strings.Contains(conflictStatus, line[:3]) { + if line[0] == 'R' || line[1] == 'R' { + _, err = bufReader.ReadString('\000') + if err != nil { + break loop + } + } + if line[0] == ' ' { continue } - conflictFiles = append(conflictFiles, line[3:]) + numFiles++ + filename := line[3 : len(line)-1] + if strings.Contains(conflictStatus, line[0:3]) { + conflictFiles = append(conflictFiles, filename[:len(filename)-1]) + } } // 4c. If there are no files changed this is an empty patch From 8098364d0e82621aacd8f11cedbafe4f26b993f5 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Fri, 9 Apr 2021 21:26:48 +0100 Subject: [PATCH 5/6] Slight restructure and better logging Signed-off-by: Andrew Thornton --- services/pull/patch.go | 230 ++++++++++++++++++++++++++--------------- 1 file changed, 145 insertions(+), 85 deletions(-) diff --git a/services/pull/patch.go b/services/pull/patch.go index 103303841ab11..5678c189ab2c4 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -120,12 +120,119 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath } // 4b. Now check git status to see if there are any conflicted files + numFiles, conflictFiles, err := doGitStatusCheck(tmpBasePath) + if err != nil { + return false, fmt.Errorf("git status --porcelain %s: %v", pr.BaseBranch, err) + } + + // 4c. If there are no files changed this is an empty patch + if numFiles == 0 { + log.Debug("PullRequest[%d]: Patch is empty - ignoring", pr.ID) + pr.Status = models.PullRequestStatusEmpty + pr.ConflictedFiles = []string{} + pr.ChangedProtectedFiles = []string{} + return false, nil + } + + // 4d. If there are no potentially conflicted files stop + if len(conflictFiles) == 0 { + pr.ConflictedFiles = []string{} + return false, nil + } + + // 5a. Prepare the patch from diff using only the conflicted files + diffReader, cancel := doGitDiffConflictedFiles(tmpBasePath, pr, conflictFiles) + defer cancel() + + // 5b. Apply the patch against the index + stderrReader, cancel := doGitApplyCheckCached(tmpBasePath, pr, prConfig, diffReader) + defer cancel() + + pr.ConflictedFiles = make([]string, 0, 5) + conflict := false + + const empty = "error: unrecognised input" + + const prefix = "error: patch failed:" + const errorPrefix = "error: " + + conflictMap := map[string]bool{} + + // 5c. Now scan the errors from the apply but only list the first 10 conflicted files + scanner := bufio.NewScanner(stderrReader) + for len(conflictMap) < 10 && scanner.Scan() { + line := scanner.Text() + + if !strings.HasPrefix(line, errorPrefix) { + continue + } + + if strings.EqualFold(line, empty) && !conflict { + continue + } + + conflict = true + + if strings.HasPrefix(line, prefix) { + filepath := strings.TrimSpace(strings.Split(line[len(prefix):], ":")[0]) + conflictMap[filepath] = true + continue + } + + suffixLoop: + for _, suffix := range patchErrorSuffices { + if !strings.HasSuffix(line, suffix) { + continue + } + + filepath := strings.TrimSpace(strings.TrimSuffix(line[len(errorPrefix):], suffix)) + if filepath != "" { + conflictMap[filepath] = true + } + break suffixLoop + } + } + err = scanner.Err() + + if len(conflictMap) > 0 { + pr.ConflictedFiles = make([]string, 0, len(conflictMap)) + for key := range conflictMap { + pr.ConflictedFiles = append(pr.ConflictedFiles, key) + } + } + + // 6. If there is a conflict the `git apply` command will return a non-zero error code - so there will be a positive error. + if err != nil { + if conflict { + pr.Status = models.PullRequestStatusConflict + log.Trace("Found %d files conflicted: %v", len(pr.ConflictedFiles), pr.ConflictedFiles) + + return true, nil + } + return false, fmt.Errorf("git apply --check: %v", err) + } + return false, nil +} + +func doGitStatusCheck(tmpBasePath string) (int, []string, error) { + // Create a pipe statusReader, statusWriter := io.Pipe() defer func() { _ = statusReader.Close() _ = statusWriter.Close() }() + // Now run: git status --porcelain -z within the temporary repo + // This will emit a series of lines: + // + // "X" "Y" " " \000 + // "X" "Y" " " \000 \0 + // + // Where XY is the status code of the file and the second type of line is only used + // for renames or copies + // + // X and Y are in [ MARDC] + // go func() { stderr := &strings.Builder{} if err := git.NewCommand("status", "--porcelain", "-z").RunInDirPipeline(tmpBasePath, statusWriter, stderr); err != nil { @@ -138,59 +245,61 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath conflictFiles := []string{} numFiles := 0 + var err error + bufReader := bufio.NewReader(statusReader) loop: for { - line, err := bufReader.ReadString('\000') + var line string + line, err = bufReader.ReadString('\000') if err != nil { break loop } + if len(line) < 3 { continue } - if line[0] == 'R' || line[1] == 'R' { + + // if the file is renamed or copied then read the new file name and ignore it + // (neither file is conflicted) + if line[0] == 'R' || line[1] == 'R' || line[0] == 'C' || line[1] == 'C' { _, err = bufReader.ReadString('\000') if err != nil { break loop } } + + // If the left side is ' ' then the there cannot be conflict as the file is only on the base branch if line[0] == ' ' { continue } + + // Otherwise there has been a file change in some way - so count it numFiles++ - filename := line[3 : len(line)-1] + + // Finally if the file is in a conflict status add it to the list of conflicted files if strings.Contains(conflictStatus, line[0:3]) { - conflictFiles = append(conflictFiles, filename[:len(filename)-1]) + filename := line[3 : len(line)-1] + conflictFiles = append(conflictFiles, filename) } } - - // 4c. If there are no files changed this is an empty patch - if numFiles == 0 { - log.Debug("PullRequest[%d]: Patch is empty - ignoring", pr.ID) - pr.Status = models.PullRequestStatusEmpty - pr.ConflictedFiles = []string{} - pr.ChangedProtectedFiles = []string{} - return false, nil + if err == io.EOF { // EOF is not an error + err = nil } - // 4d. If there are no potentially conflicted files stop - if len(conflictFiles) == 0 { - pr.ConflictedFiles = []string{} - return false, nil - } + // FIXME: conflictFiles could get large if this is a particularly badly conflicting PR - maybe we need to limit this in someway? + return numFiles, conflictFiles, err +} - // 5a. Prepare the diff +func doGitDiffConflictedFiles(tmpBasePath string, pr *models.PullRequest, conflictFiles []string) (*io.PipeReader, context.CancelFunc) { diffReader, diffWriter := io.Pipe() - defer func() { - _ = diffReader.Close() - _ = diffWriter.Close() - }() args := make([]string, 0, len(conflictFiles)+5) args = append(args, "diff", "-p", pr.MergeBase, "tracking", "--") args = append(args, conflictFiles...) - // 5b. Create a plain patch from head to base + // Create a plain patch from head to base + // NB: We're not using --binary here because if it's conflicted above git will not succeed here go func() { if err := git.NewCommand(args...).RunInDirPipeline(tmpBasePath, diffWriter, nil); err != nil { log.Error("Unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) @@ -199,18 +308,23 @@ loop: } _ = diffWriter.Close() }() + return diffReader, func() { + _ = diffReader.Close() + _ = diffWriter.Close() + } +} - args = args[:0] +func doGitApplyCheckCached(tmpBasePath string, pr *models.PullRequest, prConfig *models.PullRequestsConfig, diffReader io.Reader) (*io.PipeReader, context.CancelFunc) { + args := make([]string, 0, 5) - // 5c. Prepare the arguments to apply the patch against the index + // Prepare the arguments to apply the patch against the index args = append(args, "apply", "--check", "--cached") if prConfig.IgnoreWhitespaceConflicts { args = append(args, "--ignore-whitespace") } args = append(args, "-") - pr.ConflictedFiles = make([]string, 0, 5) - // 5d. Prep the pipe: + // Prep the pipe: // - Here we could do the equivalent of: // `git apply --check --cached patch_file > conflicts` // Then iterate through the conflicts. However, that means storing all the conflicts @@ -219,13 +333,8 @@ loop: // `git apply --check ... | grep ...` // meaning we don't store all of the conflicts unnecessarily. stderrReader, stderrWriter := io.Pipe() - defer func() { - _ = stderrReader.Close() - _ = stderrWriter.Close() - }() - // 5e. Run the apply --check command - conflict := false + // Run the apply --check command go func() { if err := git.NewCommand(args...).RunInDirTimeoutEnvFullPipeline(nil, -1, tmpBasePath, nil, stderrWriter, diffReader); err != nil { _ = stderrWriter.CloseWithError(err) @@ -233,60 +342,11 @@ loop: } _ = stderrWriter.Close() }() - const empty = "error: unrecognised input" - const prefix = "error: patch failed:" - const errorPrefix = "error: " - - conflictMap := map[string]bool{} - - // 5f. Now scan the output from the command - scanner := bufio.NewScanner(stderrReader) - for scanner.Scan() { - line := scanner.Text() - if strings.EqualFold(line, empty) && !conflict { - // ignore - } else if strings.HasPrefix(line, prefix) { - conflict = true - filepath := strings.TrimSpace(strings.Split(line[len(prefix):], ":")[0]) - conflictMap[filepath] = true - } else if strings.HasPrefix(line, errorPrefix) { - conflict = true - for _, suffix := range patchErrorSuffices { - if strings.HasSuffix(line, suffix) { - filepath := strings.TrimSpace(strings.TrimSuffix(line[len(errorPrefix):], suffix)) - if filepath != "" { - conflictMap[filepath] = true - } - break - } - } - } - // only list 10 conflicted files - if len(conflictMap) >= 10 { - break - } - } - err = scanner.Err() - - if len(conflictMap) > 0 { - pr.ConflictedFiles = make([]string, 0, len(conflictMap)) - for key := range conflictMap { - pr.ConflictedFiles = append(pr.ConflictedFiles, key) - } - } - - // 6. If there is a conflict the `git apply` command will return a non-zero error code - so there will be a positive error. - if err != nil { - if conflict { - pr.Status = models.PullRequestStatusConflict - log.Trace("Found %d files conflicted: %v", len(pr.ConflictedFiles), pr.ConflictedFiles) - - return true, nil - } - return false, fmt.Errorf("git apply --check: %v", err) + return stderrReader, func() { + _ = stderrReader.Close() + _ = stderrWriter.Close() } - return false, nil } // CheckFileProtection check file Protection From d2b241c31c401405b36543ec7d70737f546c7707 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 16 May 2021 02:15:27 +0200 Subject: [PATCH 6/6] add conflictStatus info ref --- services/pull/patch.go | 1 + 1 file changed, 1 insertion(+) diff --git a/services/pull/patch.go b/services/pull/patch.go index 5678c189ab2c4..ab999bc69f742 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -96,6 +96,7 @@ func TestPatch(pr *models.PullRequest) error { return nil } +// conflictStatus info can be found at https://git-scm.com/docs/git-status#_short_format const conflictStatus = "DD AU UD UA DU AA UU " func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath string) (bool, error) {