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(forge): pre-emptively create lib dir if it doesn't exist for updating submodules #6521

Merged
merged 8 commits into from
Dec 4, 2023
27 changes: 23 additions & 4 deletions crates/forge/bin/cmd/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,31 @@ impl DependencyInstallOpts {
let install_lib_dir = config.install_lib_dir();
let libs = git.root.join(install_lib_dir);

if dependencies.is_empty() && !self.no_git {
// Pre-emptively create the directory where deps will be installed if it's missing
fs::create_dir_all(&libs)?;

// Only update submodule deps if there are no other deps to install, we're using git
// and an appropiate .gitmodules file exists.
if dependencies.is_empty() && !self.no_git && git.root.join(".gitmodules").exists() {
p_println!(!self.quiet => "Updating dependencies in {}", libs.display());
// recursively fetch all submodules (without fetching latest)
git.submodule_update(false, false, false, true, Some(&libs))?;

let empty_install_dir = libs.read_dir()?.next().is_none();

if !empty_install_dir {
fs::create_file(libs.join(".keep"))?;
// Update the git project with the newly created folder if we're using git.
git.add(Some(&libs.join(".keep")))?;
Evalir marked this conversation as resolved.
Show resolved Hide resolved
// recursively fetch all submodules (without fetching latest)
git.submodule_update(false, false, false, true, Some(&libs))?;
// remove the temporary file
fs::remove_file(libs.join(".keep"))?;
// Update the git project with the newly deleted folder if we're using git.
git.add(Some(&libs.join(".keep")))?;
} else {
// just recursively fetch all submodules (without fetching latest)
git.submodule_update(false, false, false, true, Some(&libs))?;
}
}
fs::create_dir_all(&libs)?;

let installer = Installer { git, no_commit };
for dep in dependencies {
Expand Down