testPatch checks if patch can be merged to base repository without conflict. FIXME: make a mechanism to clean up stable local copies.
()
| 395 | // testPatch checks if patch can be merged to base repository without conflict. |
| 396 | // FIXME: make a mechanism to clean up stable local copies. |
| 397 | func (pr *PullRequest) testPatch() (err error) { |
| 398 | if pr.BaseRepo == nil { |
| 399 | pr.BaseRepo, err = GetRepositoryByID(pr.BaseRepoID) |
| 400 | if err != nil { |
| 401 | return errors.Newf("GetRepositoryByID: %v", err) |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | patchPath, err := pr.BaseRepo.PatchPath(pr.Index) |
| 406 | if err != nil { |
| 407 | return errors.Newf("BaseRepo.PatchPath: %v", err) |
| 408 | } |
| 409 | |
| 410 | // Fast fail if patch does not exist, this assumes data is corrupted. |
| 411 | if !osutil.IsFile(patchPath) { |
| 412 | log.Trace("PullRequest[%d].testPatch: ignored corrupted data", pr.ID) |
| 413 | return nil |
| 414 | } |
| 415 | |
| 416 | repoWorkingPool.CheckIn(com.ToStr(pr.BaseRepoID)) |
| 417 | defer repoWorkingPool.CheckOut(com.ToStr(pr.BaseRepoID)) |
| 418 | |
| 419 | log.Trace("PullRequest[%d].testPatch (patchPath): %s", pr.ID, patchPath) |
| 420 | |
| 421 | if err := pr.BaseRepo.UpdateLocalCopyBranch(pr.BaseBranch); err != nil { |
| 422 | return errors.Newf("UpdateLocalCopy [%d]: %v", pr.BaseRepoID, err) |
| 423 | } |
| 424 | |
| 425 | args := []string{"apply", "--check"} |
| 426 | if pr.BaseRepo.PullsIgnoreWhitespace { |
| 427 | args = append(args, "--ignore-whitespace") |
| 428 | } |
| 429 | args = append(args, patchPath) |
| 430 | |
| 431 | pr.Status = PullRequestStatusChecking |
| 432 | _, stderr, err := process.ExecDir(-1, pr.BaseRepo.LocalCopyPath(), |
| 433 | fmt.Sprintf("testPatch (git apply --check): %d", pr.BaseRepo.ID), |
| 434 | "git", args...) |
| 435 | if err != nil { |
| 436 | log.Trace("PullRequest[%d].testPatch (apply): has conflict\n%s", pr.ID, stderr) |
| 437 | pr.Status = PullRequestStatusConflict |
| 438 | return nil |
| 439 | } |
| 440 | return nil |
| 441 | } |
| 442 | |
| 443 | // NewPullRequest creates new pull request with labels for repository. |
| 444 | func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []string, pr *PullRequest, patch []byte) (err error) { |