|
8 | 8 | "fmt" |
9 | 9 | "os" |
10 | 10 | "path" |
| 11 | + "path/filepath" |
| 12 | + "strconv" |
11 | 13 | "strings" |
12 | 14 | "time" |
13 | 15 |
|
@@ -428,17 +430,22 @@ func (pr *PullRequest) testPatch() (err error) { |
428 | 430 |
|
429 | 431 | log.Trace("PullRequest[%d].testPatch (patchPath): %s", pr.ID, patchPath) |
430 | 432 |
|
431 | | - // Delete old temp local copy before we create a new temp local copy |
432 | | - RemoveAllWithNotice("Deleting old local copy", pr.BaseRepo.LocalCopyPath()) |
| 433 | + pr.Status = PullRequestStatusChecking |
| 434 | + |
| 435 | + indexTmpPath := filepath.Join(os.TempDir(), "gitea-"+pr.BaseRepo.Name+"-"+strconv.Itoa(time.Now().Nanosecond())) |
| 436 | + defer os.Remove(indexTmpPath) |
433 | 437 |
|
434 | | - if err := pr.BaseRepo.UpdateLocalCopyBranch(pr.BaseBranch); err != nil { |
435 | | - return fmt.Errorf("UpdateLocalCopy: %v", err) |
| 438 | + var stderr string |
| 439 | + _, stderr, err = process.ExecDirEnv(-1, "", fmt.Sprintf("testPatch (git read-tree): %d", pr.BaseRepo.ID), |
| 440 | + []string{"GIT_DIR=" + pr.BaseRepo.RepoPath(), "GIT_INDEX_FILE=" + indexTmpPath}, |
| 441 | + "git", "read-tree", pr.BaseBranch) |
| 442 | + if err != nil { |
| 443 | + return fmt.Errorf("git read-tree --index-output=%s %s: %v - %s", indexTmpPath, pr.BaseBranch, err, stderr) |
436 | 444 | } |
437 | 445 |
|
438 | | - pr.Status = PullRequestStatusChecking |
439 | | - _, stderr, err := process.ExecDir(-1, pr.BaseRepo.LocalCopyPath(), |
440 | | - fmt.Sprintf("testPatch (git apply --check): %d", pr.BaseRepo.ID), |
441 | | - "git", "apply", "--check", patchPath) |
| 446 | + _, stderr, err = process.ExecDirEnv(-1, "", fmt.Sprintf("testPatch (git apply --check): %d", pr.BaseRepo.ID), |
| 447 | + []string{"GIT_INDEX_FILE=" + indexTmpPath, "GIT_DIR=" + pr.BaseRepo.RepoPath()}, |
| 448 | + "git", "apply", "--check", "--cached", patchPath) |
442 | 449 | if err != nil { |
443 | 450 | for i := range patchConflicts { |
444 | 451 | if strings.Contains(stderr, patchConflicts[i]) { |
|
0 commit comments