Skip to content

fix: --web opens a browser tab for every PR when submitting a multi-branch stack#135

Open
mvanhorn wants to merge 1 commit into
boneskull:mainfrom
mvanhorn:fix/44-gh-stack-web-tabs
Open

fix: --web opens a browser tab for every PR when submitting a multi-branch stack#135
mvanhorn wants to merge 1 commit into
boneskull:mainfrom
mvanhorn:fix/44-gh-stack-web-tabs

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

Implement the maintainer's option 1 combined with option 5's URL-printing half, which the code already satisfies: only append to prURLs in the prActionCreate non-adopted path (the Created PR #%d branch), and stop appending in the prActionUpdate and adoption paths (both prActionAdopt and the adopted result of executePRCreate), since those PRs already existed and their URLs are already printed inline via s.Hyperlink/PRURL in the status lines. Update the --web flag help string in cmd/submit.go from "open created/updated PRs in web browser" to reflect the new behavior ("open newly created PRs in web browser"), and update the matching --web row in README.md's flag table (line ~290). Add/extend unit tests in cmd/submit_internal_test.go covering which actions collect URLs for opening.

Why this matters

gh stack submit --web opens a separate browser tab for every PR that was created, adopted, or updated in the stack, so a stack of N branches carpet-bombs the user with N tabs. The maintainer (repo owner, who filed the issue) pinpointed the code: in cmd/submit.go, every successful prActionUpdate, prActionAdopt, and prActionCreate branch appends ghClient.PRURL(...) to a prURLs slice, and a final loop calls browser.Browse() on each URL. The issue lists five candidate directions and names option 1 ("only open newly created PRs - skip updated ones, since the user already knows about those") as the least disruptive; a follow-up comment adds that removing --web entirely would also be acceptable.

See #44.

Testing

  • Stack submit where all branches create new PRs: every created PR URL is collected for browser opening. - Stack submit where all PRs already exist and are only updated (base changes, stack comments): no browser tabs are opened; URLs still appear in terminal output. - Mixed stack (some created, some updated, one adopted): only the newly created PRs are opened; updated and adopted PRs are not. - --web with a create failure on one branch: failed branch contributes no URL, remaining created PRs still open.

Fixes #44

@boneskull

Copy link
Copy Markdown
Owner

@mvanhorn Thanks for your help! Glad you are finding this useful.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts gh stack submit --web to only open browser tabs for newly created PRs (not updated/adopted ones), aligning behavior with the intended UX for multi-branch stacks.

Changes:

  • Restricts --web URL collection to newly created PRs via collectSubmitPRURL, and updates CLI help text accordingly.
  • Updates README flag documentation for the refined --web behavior.
  • Adds unit tests to verify which PR actions contribute URLs for browser opening.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
README.md Updates --web flag documentation to “newly created PRs” only.
cmd/submit.go Stops collecting URLs for updated/adopted PRs; collects URLs only for successfully created PRs.
cmd/submit_internal_test.go Adds unit tests covering URL collection behavior for --web across create/update/adopt/failure/dry-run cases.
cmd/restack.go Adds early return for non-conflict rebase errors (plus suggested improvement to error context).
cmd/adopt.go Refactors cycle detection to walk parent links directly (not described in PR scope).
.osc-metadata/sync.json Adds fork-sync metadata file (appears unrelated to feature change).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/restack.go
Comment on lines +299 to +301
if rebaseErr != nil && !g.IsRebaseInProgress() {
return rebaseErr
}
Comment thread cmd/adopt.go
Comment on lines +87 to 105
// Check for cycles by walking configured parent links directly. A broken
// parent can disconnect branches from the trunk-rooted tree while their
// stackParent links still form a cycle.
seen := map[string]bool{}
for current := parent; current != trunk; {
if current == branchName {
return errors.New("cannot adopt: would create a cycle")
}
if seen[current] {
return errors.New("cannot adopt: parent chain contains a cycle")
}
seen[current] = true

parentNode := tree.FindNode(root, parent)
if parentNode != nil {
for _, ancestor := range tree.GetAncestors(parentNode) {
if ancestor.Name == branchName {
return errors.New("cannot adopt: would create a cycle")
}
next, parentErr := cfg.GetParent(current)
if parentErr != nil {
break
}
current = next
}
Comment thread .osc-metadata/sync.json
Comment on lines +1 to +5
{
"fork_synced_at": "2026-07-10T09:11:21.236884+00:00",
"commits_behind_before_sync": 24,
"action_taken": "synced"
} No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--web flag opens a browser tab for every PR when submitting a multi-branch stack

3 participants