Repository navigation
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a --force flag to the PR transfer command that enables transferring PRs with conflicts by creating a PR with conflict markers and .rej files, providing more flexibility when handling complex patch applications that don't apply cleanly.
- Added
--force/-fflag to PR transfer command - Modified conflict handling to create PRs with conflict markers when
--forceis enabled - Enhanced commit messages to warn about included conflicts
- Updated help text with force flag usage examples
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| pkg/cli/pr_command.go | Added --force flag parameter throughout transfer flow, implemented conflict handling logic with --reject option, and enhanced commit messages to indicate presence of conflicts |
| pkg/cli/pr_command_test.go | Added test to verify --force flag exists on transfer subcommand |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if verbose { | ||
| fmt.Fprintln(os.Stderr, console.FormatWarningMessage("Applying patch with --reject to create conflict markers...")) | ||
| } | ||
| rejectCmd := exec.Command("git", "apply", "--reject", patchFile) |
There was a problem hiding this comment.
The rejectCmd variable is declared twice in the same code path. It's first declared on line 376 (inside the verbose block) and then redeclared on line 393 (in the force mode block). While this works due to Go's scoping rules, it could lead to confusion.
Consider using a single declaration or using different variable names to make the code clearer.
| rejFilesCmd := exec.Command("sh", "-c", "find . -name '*.rej' -type f") | ||
| rejFilesOutput, _ := rejFilesCmd.Output() | ||
| hasConflicts := len(strings.TrimSpace(string(rejFilesOutput))) > 0 | ||
|
|
There was a problem hiding this comment.
Using sh -c "find . -name '*.rej' -type f" to detect .rej files may have portability issues on Windows systems where sh might not be available. Additionally, running find from the current directory (.) could potentially search the entire repository including unrelated directories.
Consider using Go's filepath.Walk or filepath.Glob for better portability, or at least constraining the search to the git working tree with git ls-files '*.rej'.
| rejFilesCmd := exec.Command("sh", "-c", "find . -name '*.rej' -type f") | |
| rejFilesOutput, _ := rejFilesCmd.Output() | |
| hasConflicts := len(strings.TrimSpace(string(rejFilesOutput))) > 0 | |
| hasConflicts := false | |
| err := filepath.WalkDir(".", func(path string, d os.DirEntry, err error) error { | |
| if err != nil { | |
| return err | |
| } | |
| if !d.IsDir() && strings.HasSuffix(d.Name(), ".rej") { | |
| hasConflicts = true | |
| // Stop walking as soon as we find one | |
| return filepath.SkipDir | |
| } | |
| return nil | |
| }) | |
| if err != nil && verbose { | |
| fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Error searching for .rej files: %v", err))) | |
| } |
|
stale, reopen if you need to merge it. |
Summary
--forceflag for the PR transfer commandChanges
transferPRandapplyPatchToRepofunctions to support--forceflagBehavior
--force: Fail on conflicts and provide an error message--force: