Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 10, 2025

This PR implements automatic stack selection when the current branch exists in exactly one stack, eliminating the need for manual stack selection in common workflows.

Problem

Previously, users had to manually select a stack from a list even when they were working on a branch that only existed in one stack. This created unnecessary friction, especially when running multiple commands in sequence.

Solution

The stack selection logic now automatically selects a stack when the current branch is only in one stack for the remote. This mirrors Git's behavior where commands operate on the current context without requiring explicit specification.

Key Changes

  1. Enhanced SelectStack method: Added logic to detect when the current branch exists in exactly one stack and auto-select it
  2. Improved IsCurrentStack method: Now correctly identifies when a user is on the source branch of a stack (previously only checked child branches)
  3. Comprehensive test coverage: Added 6 unit tests covering all scenarios

Behavior

  • ✅ Auto-selects stack when current branch is only in one stack
  • ✅ Still displays the selected stack name to the user
  • ✅ Falls back to user prompting when branch is in multiple stacks or no stacks
  • ✅ Preserves all existing behavior (explicit --stack flag, single stack scenarios)
  • ✅ Works for both source branches and child branches

Example

# Before: Always prompted to select stack
$ stack status
? Select stack: (Use arrow keys)
  ❯ my-feature-stack
    other-stack

# After: Auto-selects when branch is only in one stack  
$ stack status
Selected stack: my-feature-stack
...

Users can still specify --stack explicitly when they want to operate on a different stack than the one containing their current branch.

Fixes #369.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…stack

Co-authored-by: geofflamrock <2915931+geofflamrock@users.noreply.github.com>
Copilot AI changed the title [WIP] Auto-select a stack if the current branch is only in that stack Auto-select stack when current branch is only in that stack Sep 10, 2025
Copilot AI requested a review from geofflamrock September 10, 2025 23:32
@geofflamrock geofflamrock marked this pull request as ready for review September 11, 2025 07:30
@geofflamrock geofflamrock merged commit d6a20ea into main Sep 11, 2025
15 checks passed
@geofflamrock geofflamrock deleted the copilot/fix-369 branch September 11, 2025 07:36
@geofflamrock geofflamrock added the enhancement New feature or request label Sep 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-select a stack if the current branch is only in that stack

2 participants