aboutsummaryrefslogtreecommitdiffstats
path: root/services/pull/patch.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-04-03 14:21:41 +0100
committerGitHub <noreply@github.com>2020-04-03 21:21:41 +0800
commit57cca44c5e75025bc3d51bea028ca7012557f4f5 (patch)
tree899a89f628944d56a08143f6c24fd69cb2047f90 /services/pull/patch.go
parentf685edf51073ac3be50ff00073a2432b4113bf82 (diff)
downloadgitea-57cca44c5e75025bc3d51bea028ca7012557f4f5.tar.gz
gitea-57cca44c5e75025bc3d51bea028ca7012557f4f5.zip
Generate Diff and Patch direct from Pull head (#10936)
* Generate Diff and Patch direct from Pull head Fix #10932 Also fix "Empty Diff/Patch File when pull is merged" Closes #10934 Signed-off-by: Andrew Thornton <art27@cantab.net> * Add tests to ensure that diff does not change Signed-off-by: Andrew Thornton <art27@cantab.net> * Ensure diffs and pulls pages work if head branch is deleted too Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services/pull/patch.go')
-rw-r--r--services/pull/patch.go21
1 files changed, 4 insertions, 17 deletions
diff --git a/services/pull/patch.go b/services/pull/patch.go
index 96145fcd92..776bfdb751 100644
--- a/services/pull/patch.go
+++ b/services/pull/patch.go
@@ -21,30 +21,17 @@ import (
// DownloadDiffOrPatch will write the patch for the pr to the writer
func DownloadDiffOrPatch(pr *models.PullRequest, w io.Writer, patch bool) error {
- // Clone base repo.
- tmpBasePath, err := createTemporaryRepo(pr)
- if err != nil {
- log.Error("CreateTemporaryPath: %v", err)
+ if err := pr.LoadBaseRepo(); err != nil {
+ log.Error("Unable to load base repository ID %d for pr #%d [%d]", pr.BaseRepoID, pr.Index, pr.ID)
return err
}
- defer func() {
- if err := models.RemoveTemporaryPath(tmpBasePath); err != nil {
- log.Error("DownloadDiff: RemoveTemporaryPath: %s", err)
- }
- }()
- gitRepo, err := git.OpenRepository(tmpBasePath)
+ gitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
if err != nil {
return fmt.Errorf("OpenRepository: %v", err)
}
defer gitRepo.Close()
-
- pr.MergeBase, err = git.NewCommand("merge-base", "--", "base", "tracking").RunInDir(tmpBasePath)
- if err != nil {
- pr.MergeBase = "base"
- }
- pr.MergeBase = strings.TrimSpace(pr.MergeBase)
- if err := gitRepo.GetDiffOrPatch(pr.MergeBase, "tracking", w, patch); err != nil {
+ if err := gitRepo.GetDiffOrPatch(pr.MergeBase, pr.GetGitRefName(), w, patch); 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: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)
}