From a71daa7ea31467b765ad13daa065e069b6731a34 Mon Sep 17 00:00:00 2001 From: Phil Stainer Date: Tue, 5 Aug 2025 08:19:19 +0100 Subject: [PATCH 1/3] fix: quote paths in git commands to allow spaces --- src/helpers/git.ts | 8 ++++---- src/helpers/worktree/addNewWorktree.ts | 2 +- src/helpers/worktree/addRemoteWorktree.ts | 4 ++-- src/helpers/worktree/removeWorktree.ts | 4 ++-- src/helpers/worktree/renameWorktree.ts | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/helpers/git.ts b/src/helpers/git.ts index 97d3992..ed0e40f 100644 --- a/src/helpers/git.ts +++ b/src/helpers/git.ts @@ -61,7 +61,7 @@ const hasBareRepository = async () => { }; export const setUpBareRepositoryFetch = async (path?: string) => { - const pathCommand = path ? `-C ${path}` : ''; + const pathCommand = path ? `-C "${path}"` : ''; const fetchOriginCommand = `git ${pathCommand} config remote.origin.fetch "${BARE_REPOSITORY_REMOTE_ORIGIN_FETCH}"`; try { @@ -84,7 +84,7 @@ export const setUpBareRepositoryFetch = async (path?: string) => { }; export const fetch = async (path?: string) => { - const pathCommand = path ? `-C ${path}` : ''; + const pathCommand = path ? `-C "${path}"` : ''; const hasBareRepo = await hasBareRepository(); if (hasBareRepo) await setUpBareRepositoryFetch(path); @@ -153,7 +153,7 @@ export const getRemoteBranches = async (): Promise => { export const pushNewBranchToRemote = async ({ path, worktree }: IWorktree) => { try { const skipHooksFlag = settings.shouldSkipGitHooks ? '--no-verify' : ''; - const command = `git -C ${path} push ${skipHooksFlag} --set-upstream origin ${worktree}`; + const command = `git -C "${path}" push ${skipHooksFlag} --set-upstream origin ${worktree}`; await executeCommand(command); } catch (e: any) { throw Error(e); @@ -179,7 +179,7 @@ export const cloneBare = async ( baseDirectory: string = './.bare' ) => { try { - const command = `git -C ${path} clone --bare "${url}" ${baseDirectory}`; + const command = `git -C "${path}" clone --bare "${url}" ${baseDirectory}`; await executeCommand(command); } catch (e: any) { throw Error(e); diff --git a/src/helpers/worktree/addNewWorktree.ts b/src/helpers/worktree/addNewWorktree.ts index 72f119a..568d0cf 100644 --- a/src/helpers/worktree/addNewWorktree.ts +++ b/src/helpers/worktree/addNewWorktree.ts @@ -15,7 +15,7 @@ export const addNewWorktree = async ( const newWorktree = { worktree: newBranch, path: newWorktreePath }; try { - const addCommand = `git worktree add --track -B ${newBranch} ${newWorktreePath} origin/${trackingBranch}`; + const addCommand = `git worktree add --track -B ${newBranch} "${newWorktreePath}" origin/${trackingBranch}`; await executeCommand(addCommand); diff --git a/src/helpers/worktree/addRemoteWorktree.ts b/src/helpers/worktree/addRemoteWorktree.ts index 6b1b380..be93a80 100644 --- a/src/helpers/worktree/addRemoteWorktree.ts +++ b/src/helpers/worktree/addRemoteWorktree.ts @@ -12,10 +12,10 @@ export const addRemoteWorktree = async (remoteBranch: string) => { const newWorktree = { worktree: remoteBranch, path: newWorktreePath }; try { - const worktreeAddCommand = `git worktree add --track -B ${remoteBranch} ${newWorktreePath} origin/${remoteBranch}`; + const worktreeAddCommand = `git worktree add --track -B ${remoteBranch} "${newWorktreePath}" origin/${remoteBranch}`; await executeCommand(worktreeAddCommand); - const pullCommand = `git -C ${newWorktreePath} pull`; + const pullCommand = `git -C "${newWorktreePath}" pull`; await executeCommand(pullCommand); return newWorktree; diff --git a/src/helpers/worktree/removeWorktree.ts b/src/helpers/worktree/removeWorktree.ts index 2d346a8..b0da6b4 100644 --- a/src/helpers/worktree/removeWorktree.ts +++ b/src/helpers/worktree/removeWorktree.ts @@ -7,7 +7,7 @@ const untrackedOrModifiedFilesError = 'contains modified or untracked files, use --force to delete it'; export const removeWorktree = async ({ worktree, path }: IWorktree) => { - const command = `git worktree remove ${path}`; + const command = `git worktree remove "${path}"`; try { await executeCommand(command); @@ -30,7 +30,7 @@ export const removeWorktree = async ({ worktree, path }: IWorktree) => { if (answer !== buttonName) return; - const forceCommand = `git worktree remove -f ${worktree}`; + const forceCommand = `git worktree remove -f "${worktree}"`; try { await executeCommand(forceCommand); showUserMessage( diff --git a/src/helpers/worktree/renameWorktree.ts b/src/helpers/worktree/renameWorktree.ts index 4b3049e..f609e35 100644 --- a/src/helpers/worktree/renameWorktree.ts +++ b/src/helpers/worktree/renameWorktree.ts @@ -7,10 +7,10 @@ export const renameWorktree = async ( ) => { const newPath = path.slice().replace(`/${worktree}`, `/${newBranchName}`); - const moveWorktree = `git worktree move ${path} ${newPath}`; + const moveWorktree = `git worktree move "${path}" "${newPath}"`; await executeCommand(moveWorktree); - const renameBranch = `git -C ${newPath} branch -m ${newBranchName}`; + const renameBranch = `git -C "${newPath}" branch -m ${newBranchName}`; await executeCommand(renameBranch); return { From 934b6f0dad83aec7b115faf8db7c85e65159b6ca Mon Sep 17 00:00:00 2001 From: Phil Stainer Date: Tue, 5 Aug 2025 08:21:58 +0100 Subject: [PATCH 2/3] docs: update README for clarity on branch removal resolves #18 --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a1cf95c..c023fa2 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ Should vscode open when worktree has been renamed ### Remove Settings -Should rename branch when removing a worktree +Should remove branch when removing a worktree - `gitWorktree.worktree.removeBranch`: False @@ -153,6 +153,4 @@ Remove worktree command should allow multiple select ## Release Notes -### 1.0.0 - -Initial release +See changes here: [CHANGELOG.md](CHANGELOG.md) for release notes. From 5e03e32692e3a6d3678b9468fbfa2059debe88d8 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 5 Aug 2025 07:33:08 +0000 Subject: [PATCH 3/3] chore(release): 1.3.3 [skip ci] ## [1.3.3](https://github.com/philstainer/git-worktree/compare/v1.3.2...v1.3.3) (2025-08-05) ### Bug Fixes * quote paths in git commands to allow spaces ([a71daa7](https://github.com/philstainer/git-worktree/commit/a71daa7ea31467b765ad13daa065e069b6731a34)) ### Documentation * update README for clarity on branch removal ([934b6f0](https://github.com/philstainer/git-worktree/commit/934b6f0dad83aec7b115faf8db7c85e65159b6ca)), closes [#18](https://github.com/philstainer/git-worktree/issues/18) --- CHANGELOG.md | 10 ++++++++++ package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ad0081..902af49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## [1.3.3](https://github.com/philstainer/git-worktree/compare/v1.3.2...v1.3.3) (2025-08-05) + +### Bug Fixes + +- quote paths in git commands to allow spaces ([a71daa7](https://github.com/philstainer/git-worktree/commit/a71daa7ea31467b765ad13daa065e069b6731a34)) + +### Documentation + +- update README for clarity on branch removal ([934b6f0](https://github.com/philstainer/git-worktree/commit/934b6f0dad83aec7b115faf8db7c85e65159b6ca)), closes [#18](https://github.com/philstainer/git-worktree/issues/18) + ## [1.3.2](https://github.com/philstainer/git-worktree/compare/v1.3.1...v1.3.2) (2025-08-04) ### Code Refactoring diff --git a/package.json b/package.json index 24074be..48e8f65 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "git-worktree", "displayName": "Git Worktree", "description": "Manage git worktrees with ease", - "version": "1.3.2", + "version": "1.3.3", "publisher": "philstainer", "homepage": "https://github.com/philstainer/git-worktree/blob/main/README.md", "bugs": {