Skip to content

fix(desktop): strip Windows extended-length prefix before git clone (#3707) - #4279

Open
iroiro147 wants to merge 1 commit into
block:mainfrom
iroiro147:fix/3707-extended-path-clone
Open

fix(desktop): strip Windows extended-length prefix before git clone (#3707)#4279
iroiro147 wants to merge 1 commit into
block:mainfrom
iroiro147:fix/3707-extended-path-clone

Conversation

@iroiro147

Copy link
Copy Markdown

Fixes #3707.

Root cause

When the Windows desktop app's repos root is canonicalized, Path::canonicalize() returns a verbatim extended-length path (\\?\C:\...). In clone_project_repository_blocking, that canonical repos_root flows through repos_root.join(repo_name) and into git clone <url> <destination> — and Git for Windows rejects the verbatim prefix with fatal: could not create work tree dir '\\?\C:\...': Invalid argument, even with core.longpaths=true.

The canonical form is the correct internal representation (the containment check against repos_root legitimate on it); it simply isn't a valid argument for the external Git CLI.

Fix

Add path_for_external_command(), which strips the \\?\<DRIVE>:\ prefix on Windows (cfg(windows) branch) and passes through unchanged elsewhere. Used exactly once, at the CLI-argument boundary. Everything else — containment checks, align_unborn_head_branch, .git inspection, the path field returned to the frontend — continues to see the canonical form, so no security or behavior invariants shift.

Test coverage

  • clone_args_strip_verbatim_prefix_from_destination — the regression test the reporter asked for. On Windows CI it validates the strip; on other hosts it validates the pass-through while still exercising cfg guard logic. (The clone-destination assembly itself is cfg-agnostic and covered by existing tests; the only Windows-specific branch is the prefix strip.)
  • path_for_external_command_leaves_ordinary_absolute_paths_alone

Verification performed

  • cargo check --lib on macOS (cfg(not(windows)) branch): clean
  • rustc --edition 2021 --crate-type lib --target x86_64-pc-windows-msvc on an extracted copy of the helper (cfg(windows) branch): clean. This caught a real bug during review — the initial draft used prefix_component.kind as if it were a field; it's a method (prefix_component.kind()). The full cross-target cargo check can't complete on macOS because some transitive deps need a Windows C toolchain (ring); the isolated-rustc route exercises the exact production code under the Windows cfg without the C-dep surface.
  • cargo test --lib project_git_workflow::tests: 14/14 pass (12 prior + 2 new)
  • cargo clippy --lib: zero warnings

…lock#3707)

On Windows, `Path::canonicalize()` returns an extended-length path
(`\\?\C:\...`). When `canonicalize_repos_root`'s output flows into
`clone_project_repository_blocking` as the `repo_dir` destination passed to
the `git clone` CLI, Git for Windows rejects the verbatim prefix with
"Invalid argument" — even with `core.longpaths` set. The canonical form is a
deliberate internal security check (containment under the configured repos
root); it just isn't a valid external CLI argument.

Add a `path_for_external_command()` helper that converts a verbatim-prefixed
absolute path to its ordinary fully-qualified form (`C:\Users\...`) on
Windows and is a pass-through elsewhere. Use it once, at the boundary where
the destination is turned into a CLI argument — every other internal use of
`repo_dir` (containment checks, `align_unborn_head_branch`, the
`ProjectRepoCloneResult.path` returned to the frontend) keeps the canonical
form unchanged.

Test coverage:
- `clone_args_strip_verbatim_prefix_from_destination` (the Windows regression
  the reporter asked for; on Windows CI it validates the strip, elsewhere it
  validates the pass-through)
- `path_for_external_command_leaves_ordinary_absolute_paths_alone`

Verification performed:
- `cargo check --lib` on macOS (cfg(not(windows)) branch): clean
- `rustc --edition 2021 --crate-type lib --target x86_64-pc-windows-msvc`
  on an extracted copy of the helper (cfg(windows) branch): clean (caught
  and fixed a `prefix_component.kind` field-vs-method bug during review)
- `cargo test --lib project_git_workflow::tests`: 14/14 pass
- `cargo clippy --lib`: zero warnings

Closes block#3707.

Signed-off-by: Sarthak Singh <sarthak.singh@juspay.in>
@Inovvia

Inovvia commented Aug 2, 2026

Copy link
Copy Markdown

@iroiro147 I cloned and built your branch and i was able to clone!

@iroiro147

Copy link
Copy Markdown
Author

Thanks for the independent verification, @Inovvia — glad the clone path works end-to-end on a real Windows environment. That was the missing confirmation from #3707.

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] Windows Projects clone passes a \?\ extended path to Git and fails with Invalid argument

2 participants