Refactor getpatch/getdiff functions and remove unnecessary fallback (#32817)
Extract from #32786 `git diff a..b` is equal to `git diff a b` which is different from `git diff a...b`. For pull request, we should always --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
6d5aa9218e
commit
b8b690feb9
3 changed files with 24 additions and 67 deletions
|
@ -41,9 +41,19 @@ func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io
|
|||
}
|
||||
defer closer.Close()
|
||||
|
||||
if err := gitRepo.GetDiffOrPatch(pr.MergeBase, pr.GetGitRefName(), w, patch, binary); 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)
|
||||
return fmt.Errorf("Unable to get patch file from %s to %s in %s Error: %w", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)
|
||||
compareArg := pr.MergeBase + "..." + pr.GetGitRefName()
|
||||
switch {
|
||||
case patch:
|
||||
err = gitRepo.GetPatch(compareArg, w)
|
||||
case binary:
|
||||
err = gitRepo.GetDiffBinary(compareArg, w)
|
||||
default:
|
||||
err = gitRepo.GetDiff(compareArg, w)
|
||||
}
|
||||
|
||||
if 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)
|
||||
return fmt.Errorf("unable to get patch file from %s to %s in %s Error: %w", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -354,7 +364,7 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo *
|
|||
_ = util.Remove(tmpPatchFile.Name())
|
||||
}()
|
||||
|
||||
if err := gitRepo.GetDiffBinary(pr.MergeBase, "tracking", tmpPatchFile); err != nil {
|
||||
if err := gitRepo.GetDiffBinary(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: %w", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue