Skip to content

fix: correct worktree path handling on Windows#1665

Open
Valley-15 wants to merge 3 commits intogeneralaction:mainfrom
Valley-15:fix/worktree-path-windows
Open

fix: correct worktree path handling on Windows#1665
Valley-15 wants to merge 3 commits intogeneralaction:mainfrom
Valley-15:fix/worktree-path-windows

Conversation

@Valley-15
Copy link
Copy Markdown
Contributor

@Valley-15 Valley-15 commented Apr 5, 2026

Summary

Fixes incorrect worktree path handling on Windows environments.

Previously, path normalization was inconsistent, which could lead to invalid or broken paths when executing commands via SSH or local shell. This change ensures paths are properly normalized before execution.

Fixes

Fixes #1641

Snapshot

N/A (backend/service-level fix, no UI changes)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore
  • New feature
  • Breaking change
  • Refactor
  • This change requires a documentation update

Mandatory Tasks

  • I have self-reviewed the code

Checklist

  • I have read the contributing guide
  • I have commented my code where necessary
  • I have checked if my PR needs changes to the documentation
  • I have added tests that prove my fix is effective

Summary by CodeRabbit

  • Bug Fixes
    • Normalize Windows-style backslashes in working-directory strings before running remote commands (applies to primary and fallback execution paths). This improves compatibility and reduces failures when using complex, quoted, or backslash-containing paths, increasing remote command reliability.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 5, 2026

@Valley-15 is attempting to deploy a commit to the General Action Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 12d8d76d-8a38-41ae-9cb0-2284cfcd44dc

📥 Commits

Reviewing files that changed from the base of the PR and between 714c833 and 2042d4c.

📒 Files selected for processing (1)
  • src/main/services/ssh/SshService.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/services/ssh/SshService.ts

📝 Walkthrough

Walkthrough

The SshService now normalizes the optional cwd by converting Windows backslashes (\\) to forward slashes (/) before shell-quoting and interpolating it into the cd ... && ${command} fragment in both primary and CLI-fallback execution paths.

Changes

Cohort / File(s) Summary
SSH Command Sanitization
src/main/services/ssh/SshService.ts
Sanitize cwd by replacing \\ with / before quoteShellArg in both executeCommand and executeCommandViaCli, ensuring the constructed cd ... && ${command} uses forward-slash paths on Windows.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 I hopped through paths both near and far,
Swapped backslashes \ for a friendly slash /,
Quoted the route, no more double crash,
Terminals open, the path is clear,
A tiny hop — the fix is here! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: correct worktree path handling on Windows' directly and accurately describes the main change: fixing path handling issues on Windows by normalizing backslashes to forward slashes in SSH command execution.
Linked Issues check ✅ Passed The PR addresses all coding requirements from issue #1641 by normalizing Windows paths (converting backslashes to forward slashes) in both executeCommand and executeCommandViaCli methods, ensuring worktree paths are not malformed when executing commands.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing Windows path handling in SshService.ts by sanitizing the cwd argument in both SSH execution paths, with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/services/ssh/SshService.ts`:
- Around line 371-372: The fallback path handling in executeCommandViaCli is
inconsistent with executeCommand: update executeCommandViaCli to normalize
Windows backslashes to forward slashes before composing innerCommand (i.e.,
compute safeCwd = cwd ? cwd.replace(/\\/g, '/') : undefined) and then build
innerCommand using quoteShellArg(safeCwd) like the pooled path code; do not
include the double-quote escaping used elsewhere. Locate executeCommandViaCli
and replace its current safeCwd/innerCommand logic accordingly so both
executeCommand and executeCommandViaCli normalize paths the same way.
- Line 371: The sanitization line creating safeCwd is incorrectly escaping
double quotes; remove the .replace(/"/g, '\\"') call so safeCwd only normalizes
backslashes and not insert literal backslashes before double quotes. Locate the
assignment to safeCwd in SshService (the const safeCwd = ... line) and change it
to only replace backslashes with forward slashes (and keep the existing ternary
handling), ensuring that downstream quoteShellArg receives the raw double-quote
characters unescaped.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d94fc289-e798-4305-8d98-e239a7a45c08

📥 Commits

Reviewing files that changed from the base of the PR and between a31f064 and 9a78ac4.

📒 Files selected for processing (1)
  • src/main/services/ssh/SshService.ts

@Valley-15
Copy link
Copy Markdown
Contributor Author

@coderabbitai

Thanks for the review!

I’ve addressed the path normalization issues:

  • Ensured Windows paths are normalized using forward slashes
  • Applied consistent handling in both SSH execution paths

Please let me know if any further changes are needed.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get the PR diff to understand the changes
gh pr diff 1665 --repo generalaction/emdash

Length of output: 868


🏁 Script executed:

#!/bin/bash
# Get the broader context around the changed lines in SshService.ts
fd 'SshService.ts' --exec cat {}

Length of output: 18893


@Valley-15 Thanks for the update! The fix in executeCommand (the ssh2 pool path) looks correct. However, looking at the full file, I noticed that executeCommandViaCli — the fallback path used for connections not in the ssh2 pool — still uses the raw cwd without normalization:

// executeCommandViaCli — around line ~475 — still has the old code:
const innerCommand = cwd ? `cd ${quoteShellArg(cwd)} && ${command}` : command;

Since cwd is constructed on the Windows client and passed through to a remote bash command, Windows backslashes in that path would still cause failures via this fallback path. The same one-liner normalization should be applied here for consistency:

const safeCwd = cwd ? cwd.replace(/\\/g, '/') : undefined;
const innerCommand = safeCwd ? `cd ${quoteShellArg(safeCwd)} && ${command}` : command;

Could you apply the same fix there? Once that's addressed, the path normalization will be truly consistent across both SSH execution paths.

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.

[bug]: Issue with worktree path on windows

1 participant