-
-
Notifications
You must be signed in to change notification settings - Fork 2
derp #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
derp #4
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # Design: Auto-push in `gh stack pr` | ||
|
|
||
| **Date:** 2026-01-28 | ||
| **Status:** Approved | ||
|
|
||
| ## Summary | ||
|
|
||
| Modify `gh stack pr` to automatically push the current branch to the remote (with tracking) before creating or updating a PR. This removes the manual `git push` step currently required. | ||
|
|
||
| ## Motivation | ||
|
|
||
| Currently, `gh stack pr` assumes the branch already exists on the remote. If it doesn't, the GitHub API call fails. Users must remember to push before running `gh stack pr`, which adds friction to the workflow. | ||
|
|
||
| ## Design | ||
|
|
||
| ### Flow | ||
|
|
||
| ``` | ||
| gh stack pr | ||
| | | ||
| +-> Push branch to origin (force-with-lease, set upstream) | ||
| | | | ||
| | +-> Success -> Continue to PR operation | ||
| | +-> Failure -> Abort with clear error message | ||
| | | ||
| +-> Create or update PR (existing logic) | ||
| ``` | ||
|
|
||
| ### Key Behaviors | ||
|
|
||
| - Always pushes before any PR operation (create or update) | ||
| - Uses `git push -u --force-with-lease origin <branch>` | ||
| - Fails the entire command if push fails | ||
| - No new flags--this becomes the default behavior | ||
|
|
||
| ### Why Force-with-lease | ||
|
|
||
| Stacked PR workflows involve frequent rebasing. Regular `git push` would fail after every rebase. Force-with-lease allows the push while still protecting against overwriting commits you haven't seen locally. | ||
|
|
||
| ## Implementation | ||
|
|
||
| ### Changes to `internal/git/git.go` | ||
|
|
||
| Add a new method: | ||
|
|
||
| ```go | ||
| // PushWithUpstream pushes a branch to origin and sets up tracking. | ||
| // Uses --force-with-lease for safety when rebasing. | ||
| func (g *Git) PushWithUpstream(branch string) error { | ||
| return g.runInteractive("push", "-u", "--force-with-lease", "origin", branch) | ||
| } | ||
| ``` | ||
|
|
||
| ### Changes to `cmd/pr.go` | ||
|
|
||
| Insert push call in `runPR()` after validating the branch is tracked (after line ~56), before checking if PR exists: | ||
|
|
||
| ```go | ||
| // Push branch to remote (with tracking) before PR operation | ||
| fmt.Printf("Pushing %s to origin...\n", branch) | ||
| if err := g.PushWithUpstream(branch); err != nil { | ||
| return fmt.Errorf("failed to push branch: %w", err) | ||
| } | ||
| ``` | ||
|
|
||
| ### Files Changed | ||
|
|
||
| - `internal/git/git.go` - Add `PushWithUpstream` method | ||
| - `internal/git/git_test.go` - Add test for new method | ||
| - `cmd/pr.go` - Add push call before PR operations | ||
|
|
||
| ## Error Handling | ||
|
|
||
| | Scenario | Behavior | | ||
| |----------|----------| | ||
| | No network | Command fails with git's error message | | ||
| | Diverged history (remote has unseen commits) | Force-with-lease rejects push, command fails | | ||
| | No permission | Command fails with git's error message | | ||
| | Branch already up-to-date | Push succeeds quickly, continues to PR | | ||
| | First push (no tracking) | `-u` sets up tracking, succeeds | | ||
|
Comment on lines
+74
to
+80
|
||
|
|
||
| ## Testing | ||
|
|
||
| ### Unit Tests | ||
|
|
||
| Add test for `PushWithUpstream` in `git_test.go` verifying correct arguments are passed. | ||
|
|
||
| ### Manual Testing Checklist | ||
|
|
||
| - [ ] `gh stack pr` on branch not yet pushed -> pushes, creates PR | ||
| - [ ] `gh stack pr` on branch with existing PR -> pushes, updates base | ||
| - [ ] `gh stack pr` when push fails -> clear error, no PR created | ||
|
|
||
| ## Alternatives Considered | ||
|
|
||
| 1. **Error with hint** - Fail with "Branch not pushed. Run `gh stack push` first." Rejected: adds friction without benefit. | ||
|
|
||
| 2. **Interactive prompt** - Ask before pushing. Rejected: adds unnecessary step for common case. | ||
|
|
||
| 3. **Regular push (no force)** - Would fail after every rebase. Rejected: doesn't fit stacked workflow. | ||
|
|
||
| 4. **Push only when creating PR** - Leave updates alone. Rejected: inconsistent behavior, PRs wouldn't reflect local state. | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the design says to insert the push call after validating that the branch is tracked, but the "Error Handling" section below describes the first push for an untracked branch succeeding because
-usets up tracking. These two statements conflict: if tracking validation still happens beforePushWithUpstream, the first-push scenario would fail instead of succeeding, so either the validation step or the described behavior should be updated for consistency.