Add --push option to forge pr create - #156
Open
abhinavgautam01 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an opt-in --push flag to forge pr create, pushing the head branch and configuring upstream tracking before PR creation.
Changes:
- Adds reusable
git.PushBranchfunctionality. - Handles push failures.
- Adds Git and CLI tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
internal/git/git.go |
Implements branch pushing. |
internal/git/git_test.go |
Tests push behavior and validation. |
internal/cli/pr.go |
Integrates the --push flag. |
internal/cli/pr_test.go |
Tests successful and failed pushes. |
internal/cli/pr_checkout_test.go |
Extends the PR service mock. |
Suppressed comments (2)
internal/cli/pr.go:305
--headis also allowed to be a remote-qualified value such asowner:featurefor GitHub (the value is passed directly togithub.NewPullRequest.Headingithub/prs.go:199). Passing that whole value toPushBranchconstructsrefs/heads/owner:feature, which is not a valid local Git ref, soforge pr create --head owner:feature --pushalways fails before the PR can be created. Extract the local branch portion for the push while retaining the original qualified value inCreatePROpts.Head.
if err := git.PushBranch(cmd.Context(), "", resolve.RemoteName(), flagHead); err != nil {
internal/cli/pr.go:305
- This pushes to the selected remote but still sends the bare
flagHeadto the forge API. That breaks fork PRs when the remote's push target differs from the repository being resolved (for example-R upstream/repo --remote fork, or a remote with apushurl): GitHub requires the head as<fork-owner>:<branch>, so the API looks forfeaturein the upstream repo even though it was just pushed to the fork. Derive the local branch and pushed remote owner and pass the qualified head, or explicitly reject this cross-repository combination.
if err := git.PushBranch(cmd.Context(), "", resolve.RemoteName(), flagHead); err != nil {
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Author
|
Addressed both suppressed findings. Qualified heads now push only the local branch while preserving |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #152
Summary
Add an opt-in
--pushflag toforge pr create, allowing the command to push the specified head branch before creating the pull request.Changes
--pushtoforge pr creategit.PushBranchhelperUsage
forge pr create \ --title "My pull request" \ --head feature-branch \ --pushThe remote defaults to origin and respects the existing global --remote option.
Testing
All checks pass.