diff --git a/lib/src/git_backend.rs b/lib/src/git_backend.rs index 8c4a89b6d8..1d03538fc7 100644 --- a/lib/src/git_backend.rs +++ b/lib/src/git_backend.rs @@ -138,8 +138,20 @@ impl GitBackend { let extra_path = store_path.join("extra"); fs::create_dir(&extra_path).context(&extra_path)?; let target_path = store_path.join("git_target"); - fs::write(&target_path, git_repo_path.to_str().unwrap().as_bytes()) - .context(&target_path)?; + if cfg!(windows) && git_repo_path.is_relative() { + // WSL doesn't like backslashes in paths, so we manually format the path with + // forward slsashes (non-WSL is fine with forward slashes). If the path is + // absolute, there's much we can do - it simply won't work on both inside and + // outside WSL. + let git_repo_path_string = git_repo_path + .components() + .map(|component| component.as_os_str().to_str().unwrap().to_owned()) + .join("/"); + fs::write(&target_path, git_repo_path_string.as_bytes()).context(&target_path)?; + } else { + fs::write(&target_path, git_repo_path.to_str().unwrap().as_bytes()) + .context(&target_path)?; + }; let repo = git2::Repository::open(store_path.join(git_repo_path)) .map_err(GitBackendInitError::OpenRepository)?; let extra_metadata_store = TableStore::init(extra_path, HASH_LENGTH);