Skip to content

Git Worktrees: Fix remove worktree infinite loading spinner - #25394

Merged
raycastbot merged 6 commits into
raycast:mainfrom
alfredomtx:fix/git-worktrees-remove-error-handling
Feb 20, 2026
Merged

raycastbot merged 6 commits into
raycast:mainfrom
alfredomtx:fix/git-worktrees-remove-error-handling

Conversation

@alfredomtx

@alfredomtx alfredomtx commented Feb 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fix the "Remove Worktree" action showing an infinite animated toast when any unexpected git error occurs
  • Add outer try/catch to handleRemoveWorktree so all errors surface as a failure toast instead of spinning forever
  • Quote shell-interpolated paths in removeWorktree, removeBranch, and pruneWorktrees to handle paths with spaces

Root Cause

The inner try/catch in handleRemoveWorktree only handles the UNTRACKED_OR_MODIFIED_FILES_ERROR case. All other errors are re-thrown with no outer catch, causing an unhandled promise rejection — Raycast swallows these silently, leaving the animated toast spinning forever. The cleanup steps (removeBranch, pruneWorktrees) also ran outside any try/catch, so failures there caused the same issue.

Test plan

  • Remove a clean worktree → toast shows success
  • Remove a worktree with uncommitted changes → confirmation dialog → force removes or aborts cleanly
  • Any unexpected git error → toast shows failure with error message (not infinite spinner)
  • Paths with spaces work correctly

The remove worktree action shows an animated toast that never resolves
when any unexpected git error occurs. The inner try/catch only handles
the "untracked or modified files" case and re-throws everything else
with no outer catch. The cleanup steps (removeBranch, pruneWorktrees)
also run outside any try/catch.

Add an outer try/catch that surfaces all errors via a failure toast
instead of leaving the spinner running forever.

Also quote shell-interpolated paths in removeWorktree, removeBranch,
and pruneWorktrees to handle paths with spaces.
@raycastbot raycastbot added extension fix / improvement Label for PRs with extension's fix improvements extension: git-worktrees Issues related to the git-worktrees extension platform: macOS labels Feb 12, 2026
@raycastbot

ghost commented Feb 12, 2026 •

Copy link
Copy Markdown
Collaborator

Thank you for your first contribution! 🎉

🔔 @philstainer you might want to have a look.

You can use this guide to learn how to check out the Pull Request locally in order to test it.

📋 Quick checkout commands
BRANCH="fix/git-worktrees-remove-error-handling"
FORK_URL="https://github.com/alfredomtx/extensions-1.git"
EXTENSION_NAME="git-worktrees"
REPO_NAME="extensions-1"

git clone -n --depth=1 --filter=tree:0 -b $BRANCH $FORK_URL
cd $REPO_NAME
git sparse-checkout set --no-cone "extensions/$EXTENSION_NAME"
git checkout
cd "extensions/$EXTENSION_NAME"
npm install && npm run dev

We're currently experiencing a high volume of incoming requests. As a result, the initial review may take up to 10-15 business days.

@alfredomtx
alfredomtx marked this pull request as draft February 12, 2026 22:14
@greptile-apps

ghost commented Feb 12, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds outer error handling to handleRemoveWorktree to prevent infinite loading spinner, handles stale worktrees gracefully, and quotes paths in some git commands to support paths with spaces.

  • Fixed unhandled promise rejection causing infinite spinner when unexpected git errors occur
  • Added NOT_A_WORKING_TREE_ERROR detection to handle stale worktrees that no longer exist on disk
  • Wrapped cleanup steps (removeBranch, pruneWorktrees) in try/catch to prevent partial cleanup failures from showing error toast
  • Quoted path variables in removeWorktree, removeBranch, pruneWorktrees, moveWorktree, renameBranch, addRemoteWorktree, and addNewWorktree

Critical Issue: The PR description claims "Quote paths in git commands to handle paths with spaces" but only 7 out of 17 git commands with unquoted path variables were fixed. Ten additional commands in git.ts still have unquoted path or branch variables (lines 24, 116, 181, 189, 205, 231, 282, 317, 330, 343) that will break with spaces, contradicting the stated fix.

Confidence Score: 2/5

  • Incomplete fix - many git commands still vulnerable to path injection
  • The error handling improvements are solid, but the path quoting fix is incomplete. Only 7 of 17 unquoted path variables were fixed, leaving 10 git commands vulnerable to breaking with spaces. This contradicts the PR's claim that paths are quoted to handle spaces.
  • Pay close attention to extensions/git-worktrees/src/helpers/git.ts - contains 10 unquoted path/branch variables that need fixing

Important Files Changed

Filename Overview
extensions/git-worktrees/CHANGELOG.md Added changelog entry with proper {PR_MERGE_DATE} placeholder format
extensions/git-worktrees/src/config/constants.ts Added NOT_A_WORKING_TREE_ERROR constant for stale worktree detection
extensions/git-worktrees/src/components/actions/remove-worktree.tsx Added outer error handler and stale worktree handling, with graceful cleanup failure handling
extensions/git-worktrees/src/helpers/git.ts Quoted paths in some git commands, but many commands still have unquoted path variables

Last reviewed commit: 987e504

ghost 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.

2 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps

ghost commented Feb 12, 2026

Copy link
Copy Markdown
Contributor
Additional Comments (4)

extensions/git-worktrees/src/helpers/git.ts
currentName and newName should be quoted to handle paths with spaces, matching the pattern from removeWorktree, removeBranch, and pruneWorktrees

  const moveWorktree = `git -C "${path}" worktree move "${currentName}" "${newName}"`;

extensions/git-worktrees/src/helpers/git.ts
path and newBranchName should be quoted to handle paths/branches with spaces

  const renameBranch = `git -C "${path}" branch -m "${newBranchName}"`;

extensions/git-worktrees/src/helpers/git.ts
All path and branch parameters should be quoted to handle spaces

    const worktreeAddCommand = `git -C "${parentPath}" worktree add --track -B "${remoteBranch}" "${newWorktreePath}" "origin/${remoteBranch}"`;

extensions/git-worktrees/src/helpers/git.ts
All path and branch parameters should be quoted to handle spaces

    const addCommand = `git -C "${parentPath}" worktree add --track -B "${newBranch}" "${newWorktreePath}" "origin/${trackingBranch}"`;

Alfredo Menezes added 2 commits February 16, 2026 12:53
Address review feedback: quote shell-interpolated paths in
moveWorktree, renameBranch, addRemoteWorktree, and addNewWorktree
for consistency with the already-quoted functions.
When a worktree directory is already gone, `git worktree remove` fails
with "is not a working tree". Catch this error and skip to cleanup
(prune + branch delete) instead of crashing.
@alfredomtx
alfredomtx marked this pull request as ready for review February 16, 2026 21:54
@alfredomtx

ghost commented Feb 16, 2026

Copy link
Copy Markdown
Contributor Author

@greptile review

ghost 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.

4 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment thread extensions/git-worktrees/CHANGELOG.md Resolved
@alfredomtx
alfredomtx marked this pull request as draft February 17, 2026 00:30
@alfredomtx
alfredomtx marked this pull request as ready for review February 18, 2026 16:04

ghost 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.

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread extensions/git-worktrees/CHANGELOG.md Outdated
Comment on lines +3 to +8
## [Unreleased]

### Fixed
- Fix remove worktree action showing infinite loading spinner on unexpected errors
- Quote paths in git commands to handle paths with spaces

ghost Feb 19, 2026

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.

Above changes look great, one small change that is needed here

See comment: https://github.com/raycast/extensions/pull/25394/changes#r2814181016

I believe raycast changelog needs you to follow format like: ## [Fix Remove Worktree Infinite Loading] - {PR_MERGE_DATE}

ghost Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed it, thanks @philstainer!

@0xdhrv

ghost commented Feb 19, 2026

Copy link
Copy Markdown
Member

Hey @alfredomtx 👋

Can you please look into the failing checks? Also the incorrect changelog format.

References:

@0xdhrv
0xdhrv marked this pull request as draft February 19, 2026 11:58
@0xdhrv 0xdhrv self-assigned this Feb 19, 2026
@alfredomtx
alfredomtx marked this pull request as ready for review February 19, 2026 17:03

ghost 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.

4 files reviewed, 10 comments

Edit Code Review Agent Settings | Greptile

};

export const getRemoteOriginUrl = async ({ path }: { path: string }) => {
const command = `git -C ${path} remote get-url origin`;

ghost Feb 19, 2026

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.

path variable not quoted - breaks with spaces

Suggested change
const command = `git -C "${path}" remote get-url origin`;

};

export const cloneBareRepository = async ({ path, url }: { path: string; url: string }) => {
return executeCommand(`git -C ${path} clone --bare "${url}" './.bare'`);

ghost Feb 19, 2026

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.

path variable not quoted - breaks with spaces

Suggested change
return executeCommand(`git -C "${path}" clone --bare "${url}" './.bare'`);


export const fetch = async (path?: string) => {
try {
const command = `git -C ${path} fetch --all --prune`;

ghost Feb 19, 2026

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.

path variable not quoted - breaks with spaces

Suggested change
const command = `git -C "${path}" fetch --all --prune`;

};

export const checkIfBranchNameIsValid = async ({ path, name }: { path?: string; name: string }) => {
const command = `git -C ${path} check-ref-format --branch '${name}'`;

ghost Feb 19, 2026

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.

path variable not quoted - breaks with spaces

Suggested change
const command = `git -C "${path}" check-ref-format --branch '${name}'`;

options?: ExecOptions | undefined,
): Promise<string[]> => {
try {
const command = `git -C ${path} branch -r`;

ghost Feb 19, 2026

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.

path variable not quoted - breaks with spaces

Suggested change
const command = `git -C "${path}" branch -r`;

includeBare?: boolean;
showCurrentWorktree?: boolean;
}) => {
const command = `git -C ${path} worktree list`;

ghost Feb 19, 2026

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.

path variable not quoted - breaks with spaces

Suggested change
const command = `git -C "${path}" worktree list`;

try {
const { skipGitHooksWhenPushing } = getPreferences();
const noVerifyFlag = skipGitHooksWhenPushing ? " --no-verify" : "";
const command = `git -C ${path} push --set-upstream origin ${branch}${noVerifyFlag}`;

ghost Feb 19, 2026

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.

path and branch variables not quoted - breaks with spaces

Suggested change
const command = `git -C "${path}" push --set-upstream origin "${branch}"${noVerifyFlag}`;


export const checkIfBranchExistsOnRemote = async ({ path, branch }: { path: string; branch: string }) => {
try {
const command = `git -C ${path} ls-remote origin ${branch}`;

ghost Feb 19, 2026

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.

path and branch variables not quoted - breaks with spaces

Suggested change
const command = `git -C "${path}" ls-remote origin "${branch}"`;


export const getCurrentCommit = async ({ path }: { path: string }) => {
try {
const command = `git -C ${path} rev-parse HEAD`;

ghost Feb 19, 2026

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.

path variable not quoted - breaks with spaces

Suggested change
const command = `git -C "${path}" rev-parse HEAD`;


export const pullBranchChanges = async ({ path }: { path: string }) => {
try {
const command = `git -C ${path} pull`;

ghost Feb 19, 2026

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.

path variable not quoted - breaks with spaces

Suggested change
const command = `git -C "${path}" pull`;

ghost 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.

Awesome @alfredomtx

Thanks for taking the time to fix that issue, greatly appreciated 🙏

@raycast-extensions-bot raycast-extensions-bot Bot added the Approved Approved by a user label Feb 19, 2026

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me, approved 🔥

@raycastbot
raycastbot merged commit 70b764e into raycast:main Feb 20, 2026
@github-actions

ghost commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

@raycastbot

ghost commented Feb 20, 2026

Copy link
Copy Markdown
Collaborator

🎉 🎉 🎉

Such a great contribution deserves a reward, but unfortunately we couldn't find your Raycast account based on your GitHub username (@alfredomtx).

Please link your GitHub account to your Raycast account to receive your credits and soon be able to exchange them for some swag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved Approved by a user extension fix / improvement Label for PRs with extension's fix improvements extension: git-worktrees Issues related to the git-worktrees extension platform: macOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants