Skip to content

fix: handle spaces in home directory paths on Windows#94

Merged
timvw merged 4 commits into
mainfrom
fix/windows-spaces-in-home
Jun 4, 2026
Merged

fix: handle spaces in home directory paths on Windows#94
timvw merged 4 commits into
mainfrom
fix/windows-spaces-in-home

Conversation

@timvw
Copy link
Copy Markdown
Owner

@timvw timvw commented Jun 4, 2026

Summary

Fixes #93 — multiple code paths broke when the user's home folder contained spaces (e.g. C:\Users\John Doe\).

Bugs fixed:

  • expandHome: only recognized ~/ prefix, not ~\ (Windows backslash). Also added os.ExpandEnv fallback so $HOME, ${HOME}, and %USERPROFILE% are expanded in the root config value.
  • remove.go: used strings.Fields to parse git worktree list output, which splits paths on spaces. Switched to the porcelain parser (getWorktreeListPorcelain) which handles spaces correctly.
  • shellenv.go: Linux script -c "command wt $*" broke when arguments contained spaces. Now shell-quotes each argument with printf '%q'.
  • Config template: hook examples used unquoted $WT_PATH/$WT_MAIN; added quoting guidance and quoted the examples.

Test plan

  • New tests for expandHome with ~\, $VAR, ${VAR}, unset vars
  • New test for findWorktreeByBranch with spaces in paths
  • New test for porcelain parser with spaces in paths (regression for old strings.Fields approach)
  • All 397 existing tests pass
  • go vet ./... clean

- expandHome: support ~\ (backslash) prefix and expand $HOME/${HOME}/%USERPROFILE% via os.ExpandEnv
- remove: use porcelain worktree list to avoid strings.Fields splitting paths with spaces
- shellenv: shell-quote arguments in Linux script(1) invocation to preserve spaces
- config template: quote $WT_PATH/$WT_MAIN in hook examples

Closes #93
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

❌ Patch coverage is 58.06452% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 30.58%. Comparing base (c67a53e) to head (f80661d).

Files with missing lines Patch % Lines
cmd/shellenv.go 0.00% 8 Missing ⚠️
cmd/remove.go 0.00% 3 Missing ⚠️
cmd/config.go 90.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #94      +/-   ##
==========================================
+ Coverage   30.10%   30.58%   +0.48%     
==========================================
  Files          27       27              
  Lines        2787     2805      +18     
==========================================
+ Hits          839      858      +19     
+ Misses       1863     1860       -3     
- Partials       85       87       +2     
Files with missing lines Coverage Δ
cmd/config.go 70.80% <90.00%> (+2.73%) ⬆️
cmd/remove.go 0.00% <0.00%> (ø)
cmd/shellenv.go 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

timvw added 3 commits June 4, 2026 08:30
os.ExpandEnv only handles $VAR and ${VAR}. Add expandWindowsEnv for
%USERPROFILE% and similar Windows-style variables, called on Windows only.

Follow-up from Codex review of #94.
The tilde branch returned early, skipping os.ExpandEnv. Now env
expansion runs on all paths including those starting with ~.

Follow-up from Codex review round 2.
@timvw timvw merged commit 5345d77 into main Jun 4, 2026
11 checks passed
@timvw timvw deleted the fix/windows-spaces-in-home branch June 4, 2026 06:46
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.

On Windows issues if home folder has spaces

1 participant