update add cmd to adopt existing branches#101
Draft
skarim wants to merge 1 commit into
Draft
Conversation
Previously, `gh stack add` rejected any branch name that already existed in git with a blanket "branch already exists" error. This was overly restrictive — users who create branches ahead of time (e.g. from the GitHub UI or via `git branch`) had no way to incorporate them into a stack without deleting and recreating them. Now, if the specified branch exists in git but is not part of any existing stack, `add` adopts it: it skips branch creation, checks out the existing branch, and appends it to the stack metadata. This mirrors the adopt-or-create pattern already used by `gh stack init`. Branches that belong to another stack are still rejected by the existing `ValidateNoDuplicateBranch` guard, so there is no risk of cross-stack conflicts. Behavioral summary: - Existing branch, not in any stack → adopted (checkout only, no create) - Existing branch, already in a stack → error (unchanged) - Non-existent branch → created (unchanged) - Staging/commit flags (-A, -u, -m) work with adopted branches Tests added: - TestAdd_AdoptsExistingBranch - TestAdd_RejectsExistingBranchInStack - TestAdd_AdoptsExistingBranchWithCommit
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.
Allow
gh stack addto adopt existing branchesPreviously,
gh stack addrejected any branch name that already existedin git with a blanket "branch already exists" error. This was overly
restrictive — users who create branches ahead of time (e.g. from the
GitHub UI or via
git branch) had no way to incorporate them into astack without deleting and recreating them.
Now, if the specified branch exists in git but is not part of any
existing stack,
addadopts it: it skips branch creation, checks outthe existing branch, and appends it to the stack metadata. This mirrors
the adopt-or-create pattern already used by
gh stack init.Branches that belong to another stack are still rejected by the existing
ValidateNoDuplicateBranchguard, so there is no risk of cross-stackconflicts.
Behavioral summary:
Tests added:
Stack created with GitHub Stacks CLI • Give Feedback 💬