Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 28, 2025

✅ Fix: Skip child action prompt when removing branches with no children

Issue Resolved Successfully

Fixed the branch remove command to skip asking about child branch actions when the branch being removed has no children.

✅ Implementation Complete:

  • Core Issue Fixed: Modified RemoveBranchCommandHandler to check if branch has children before prompting
  • Helper Method Added: Added FindBranch() method to Stack.cs for efficient branch lookup
  • Backwards Compatibility: CLI flags --remove-children and --move-children-to-parent work as expected
  • Smart Logic: Only prompts when branch has children OR explicit action provided via CLI
  • Default Behavior: Uses RemoveBranchChildAction.RemoveChildren when no children and no explicit action
  • Removed redundant test: Cleaned up duplicate test coverage as requested in review

✅ Testing Complete:

  • 14 RemoveBranchCommandHandler tests - all passing (removed 1 redundant test)
  • 234 total tests - all passing, no regressions
  • New test coverage:
    • WhenBranchHasNoChildren_DoesNotAskForChildAction()
    • WhenBranchHasNoChildrenButRemoveChildrenIsProvided_DoesNotAskForChildAction()
    • WhenBranchHasNoChildrenButMoveChildrenToParentIsProvided_DoesNotAskForChildAction()

✅ Technical Implementation:

Files Changed:

  1. src/Stack/Config/Stack.cs - Added branch lookup methods
  2. src/Stack/Commands/Branch/RemoveBranchCommand.cs - Modified handler logic
  3. src/Stack.Tests/Commands/Branch/RemoveBranchCommandHandlerTests.cs - Added comprehensive tests, removed redundant coverage

Key Logic:

var branch = stack.FindBranch(branchName);
var hasChildren = branch?.Children.Count > 0;

if (inputs.RemoveChildrenAction.HasValue) {
    action = inputs.RemoveChildrenAction.Value; // Use explicit flag
} else if (hasChildren) {
    action = await inputProvider.Select(...); // Ask only when needed
} else {
    action = RemoveBranchChildAction.RemoveChildren; // Default for childless
}

✅ Acceptance Criteria Met:

When branch has no children, user is not asked for child action
CLI flags --remove-children and --move-children-to-parent still work
Unit tests added covering all scenarios
Redundant test coverage removed per review feedback

Ready for Review - The fix is minimal, well-tested, and addresses all feedback.

Original prompt

This section details on the original issue you should resolve

<issue_title>branch remove command asks for what to do with child branches when there are none</issue_title>
<issue_description>When a branch being removed from a stack has no children we still ask for what action to take: either "Move children branches to parent branch" or "Remove children branches". This should be skipped to avoid asking an unnecessary question.

Technical notes

  • The relevant command handler is RemoveBranchCommandHandler

Acceptance criteria

  • When a branch being removed from a stack has no children then the user should not be asked for which action they want to take for child branches.
  • The user must still be able to specifically set an action via the --remove-children or --move-children-to-parent.
  • Unit tests added for the command handler covering the functionality</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #381

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: geofflamrock <2915931+geofflamrock@users.noreply.github.com>
Copilot AI changed the title [WIP] branch remove command asks for what to do with child branches when there are none Fix: Skip child action prompt when removing branches with no children Sep 28, 2025
Copilot AI requested a review from geofflamrock September 28, 2025 22:59
}

[Fact]
public async Task WhenBranchHasChildren_StillAsksForChildAction()
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot this test is already covered by existing tests, let's remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the redundant test. You're right - the existing tests WhenChildActionIsMoveChildrenToParent_RemovesBranchAndMovesChildrenToParent() and WhenChildActionIsRemoveChildren_RemovesBranchAndDeletesChildren() already cover the scenario where branches have children and verify that the child action prompt is shown. Commit f46a399.

Co-authored-by: geofflamrock <2915931+geofflamrock@users.noreply.github.com>
Copilot AI requested a review from geofflamrock September 29, 2025 09:18
@geofflamrock geofflamrock added the bug Something isn't working label Sep 29, 2025
@geofflamrock geofflamrock changed the title Fix: Skip child action prompt when removing branches with no children Skip child action prompt when removing branches with no children Sep 29, 2025
@geofflamrock geofflamrock marked this pull request as ready for review September 29, 2025 09:30
@geofflamrock geofflamrock merged commit bec7fc9 into main Sep 29, 2025
27 checks passed
@geofflamrock geofflamrock deleted the copilot/fix-bf2466eb-e9e6-4c31-9206-f2a6606efec8 branch September 29, 2025 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

branch remove command asks for what to do with child branches when there are none

2 participants