Skip to content

Commit

Permalink
git: use forward slashes in relative path to backing git repo
Browse files Browse the repository at this point in the history
Closes #2403.
  • Loading branch information
martinvonz committed Oct 19, 2023
1 parent d92be66 commit f714afe
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/src/git_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f714afe

Please sign in to comment.