Skip to content

Refactor error handling in worktree deletion process#12

Merged
dev-ankit merged 2 commits into
mainfrom
feature/fix-delete
Jan 18, 2026
Merged

Refactor error handling in worktree deletion process#12
dev-ankit merged 2 commits into
mainfrom
feature/fix-delete

Conversation

@dev-ankit

Copy link
Copy Markdown
Owner
  • Introduced a constant EXIT_ERROR for consistent error exit codes.
  • Updated the confirmation prompt for deleting worktrees with uncommitted changes to use an error message instead of a confirmation dialog.
  • Clarified comments regarding base branch determination logic.

These changes improve the robustness and clarity of the worktree management functionality.

- Introduced a constant `EXIT_ERROR` for consistent error exit codes.
- Updated the confirmation prompt for deleting worktrees with uncommitted changes to use an error message instead of a confirmation dialog.
- Clarified comments regarding base branch determination logic.

These changes improve the robustness and clarity of the worktree management functionality.
Copilot AI review requested due to automatic review settings January 18, 2026 14:20

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

This PR aims to refactor error handling in the worktree deletion process by introducing a constant for exit codes, changing the confirmation flow for uncommitted changes, and clarifying comments about base branch logic.

Changes:

  • Introduced EXIT_ERROR constant for consistent error exit codes
  • Modified uncommitted changes handling to use error() instead of confirm() dialog
  • Updated comment for base branch determination logic to clarify when it's used

Reviewed changes

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

File Description
tools/wt-worktree/wt/worktree.py Adds EXIT_ERROR constant, refactors uncommitted changes check in delete_worktree to use error() function, and clarifies base branch comment in create_worktree
tools/wt-worktree/uv.lock Newly added dependency lock file with package specifications and checksums

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

Comment on lines +223 to +225
"use --force to delete anyway",
EXIT_ERROR)
return

Copilot AI Jan 18, 2026

Copy link

Choose a reason for hiding this comment

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

The error() function is being called with EXIT_ERROR which will call sys.exit(1), causing the program to terminate immediately. This means the return statement on line 225 will never be executed. Additionally, this creates inconsistent behavior compared to the unpushed commits check below (lines 241-246), which properly returns False when the user doesn't confirm deletion. The error handling should be refactored to either return False (allowing the caller to handle the response) or consistently use sys.exit for all validation failures.

Suggested change
"use --force to delete anyway",
EXIT_ERROR)
return
"use --force to delete anyway"
)
return False

Copilot uses AI. Check for mistakes.
Comment thread tools/wt-worktree/wt/worktree.py Outdated
# Determine base branch
if base is None:
# Determine base branch (only used when creating a new branch)
if base is None and not use_existing_branch:

Copilot AI Jan 18, 2026

Copy link

Choose a reason for hiding this comment

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

The variable use_existing_branch is referenced but is not defined in the method signature or anywhere in the function. This will cause a NameError at runtime. The function signature shows create_worktree(self, name: str, base: Optional[str] = None, detached: bool = False), so this variable should either be added as a parameter or replaced with the correct logic (possibly checking if create_branch is False).

Suggested change
if base is None and not use_existing_branch:
if base is None and create_branch:

Copilot uses AI. Check for mistakes.
return False
"use --force to delete anyway",
EXIT_ERROR)
return

Copilot AI Jan 18, 2026

Copy link

Choose a reason for hiding this comment

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

The function signature indicates a return type of bool (line 187), but when uncommitted changes are detected without force, the function now returns None (line 225) instead of False. This creates an inconsistency with the documented return type and the calling code expectations. The return statement should be return False to match the type hint and maintain consistency with the unpushed commits check on line 246.

Suggested change
return
return False

Copilot uses AI. Check for mistakes.
@dev-ankit dev-ankit merged commit 67e11be into main Jan 18, 2026
3 checks passed
@dev-ankit dev-ankit deleted the feature/fix-delete branch January 18, 2026 14:48
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.

2 participants