Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cloning in presence of missing dir #39

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/index/git_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ impl RemoteGitIndex {
let res = if let Some(repo) = repo {
(repo, None)
} else {
// We need to create the directory chain ourselves, gix will fail
// if any parent directory is missing
if !index.cache.path.exists() {
std::fs::create_dir_all(&index.cache.path).map_err(|source| {
GitError::ClonePrep(Box::new(gix::clone::Error::Init(
gix::init::Error::Init(gix::create::Error::CreateDirectory {
source,
path: index.cache.path.clone().into(),
}),
)))
})?;
}

let (repo, out) = gix::prepare_clone_bare(index.url.as_str(), &index.cache.path)
.map_err(Box::new)?
.with_remote_name("origin")
Expand Down
2 changes: 1 addition & 1 deletion tests/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn remote_index(
RemoteGitIndex::new(
GitIndex::new(IndexLocation {
url: IndexUrl::NonCratesIo(url.as_ref().as_str().into()),
root: IndexPath::Exact(path.as_ref().to_owned()),
root: IndexPath::Exact(path.as_ref().join("sub/dir")),
})
.unwrap(),
&utils::unlocked(),
Expand Down