Skip to content

Commit 7e973b3

Browse files
committed
improvements
1 parent 3d0222c commit 7e973b3

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

modules/gitrepo/merge.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ func MergeTree(ctx context.Context, repo Repository, base, ours, theirs string)
5252
// Remove last NULL-byte from conflicted file info, then split with NULL byte as separator.
5353
return treeOID, true, strings.Split(conflictedFileInfo[:len(conflictedFileInfo)-1], "\x00"), nil
5454
}
55+
56+
func DiffTree(ctx context.Context, repo Repository, treeHash, mergeBase string) error {
57+
return gitcmd.NewCommand("diff-tree", "--quiet").AddDynamicArguments(treeHash, mergeBase).
58+
Run(ctx, &gitcmd.RunOpts{
59+
Dir: repoPath(repo),
60+
})
61+
}

services/pull/conflicts.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func checkPullRequestMergeableAndUpdateStatus(ctx context.Context, pr *issues_mo
2929
// checkConflictsMergeTree uses git merge-tree to check for conflicts and if none are found checks if the patch is empty
3030
// return true if there is conflicts otherwise return false
3131
// pr.Status and pr.ConflictedFiles will be updated as necessary
32-
func checkConflictsMergeTree(ctx context.Context, repoPath string, pr *issues_model.PullRequest, baseCommitID string) (bool, error) {
32+
func checkConflictsMergeTree(ctx context.Context, pr *issues_model.PullRequest, baseCommitID string) (bool, error) {
3333
treeHash, conflict, conflictFiles, err := gitrepo.MergeTree(ctx, pr.BaseRepo, pr.MergeBase, baseCommitID, pr.HeadCommitID)
3434
if err != nil {
3535
return false, fmt.Errorf("MergeTree: %w", err)
@@ -47,10 +47,7 @@ func checkConflictsMergeTree(ctx context.Context, repoPath string, pr *issues_mo
4747
// will return exit code 0 if there's no diff and exit code 1 if there's
4848
// a diff.
4949
isEmpty := true
50-
if err = gitcmd.NewCommand("diff-tree", "--quiet").AddDynamicArguments(treeHash, pr.MergeBase).
51-
Run(ctx, &gitcmd.RunOpts{
52-
Dir: repoPath,
53-
}); err != nil {
50+
if err = gitrepo.DiffTree(ctx, pr.BaseRepo, treeHash, pr.MergeBase); err != nil {
5451
if !gitcmd.IsErrorExitCode(err, 1) {
5552
return false, fmt.Errorf("DiffTree: %w", err)
5653
}
@@ -120,7 +117,7 @@ func checkPullRequestMergeableAndUpdateStatusMergeTree(ctx context.Context, pr *
120117
}
121118

122119
// 5. Check for conflicts
123-
conflicted, err := checkConflictsMergeTree(ctx, pr.BaseRepo.RepoPath(), pr, baseCommitID)
120+
conflicted, err := checkConflictsMergeTree(ctx, pr, baseCommitID)
124121
if err != nil {
125122
log.Error("checkConflictsMergeTree: %v", err)
126123
pr.Status = issues_model.PullRequestStatusEmpty // if there is no merge base, then it's empty but we still need to allow the pull request created

0 commit comments

Comments
 (0)