Skip to content

Commit

Permalink
don't default to recursive submodule updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswenzel authored and GitHub Actions Bot committed Oct 16, 2023
1 parent dbd935b commit c1f15c7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
14 changes: 13 additions & 1 deletion crates/cli/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ https://github.com/foundry-rs/foundry/issues/new/choose"
force: bool,
remote: bool,
no_fetch: bool,
recursive: bool,
paths: I,
) -> Result<()>
where
Expand All @@ -571,16 +572,27 @@ https://github.com/foundry-rs/foundry/issues/new/choose"
{
self.cmd()
.stderr(self.stderr())
.args(["submodule", "update", "--progress", "--init", "--recursive"])
.args(["submodule", "update", "--progress", "--init"])
.args(self.shallow.then_some("--depth=1"))
.args(force.then_some("--force"))
.args(remote.then_some("--remote"))
.args(no_fetch.then_some("--no-fetch"))
.args(recursive.then_some("--recursive"))
.args(paths)
.exec()
.map(drop)
}

pub fn submodule_foreach(self, recursive: bool, cmd: impl AsRef<OsStr>) -> Result<()> {
self.cmd()
.stderr(self.stderr())
.args(["submodule", "foreach"])
.args(recursive.then_some("--recursive"))
.arg(cmd)
.exec()
.map(drop)
}

pub fn submodule_init(self) -> Result<()> {
self.cmd().stderr(self.stderr()).args(["submodule", "init"]).exec().map(drop)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl InitArgs {
git.submodule_init()?;
} else {
// if not shallow, initialize and clone submodules (without fetching latest)
git.submodule_update(false, false, true, None::<PathBuf>)?;
git.submodule_update(false, false, true, true, None::<PathBuf>)?;
}
} else {
// if target is not empty
Expand Down
7 changes: 4 additions & 3 deletions crates/forge/bin/cmd/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ impl DependencyInstallOpts {

if dependencies.is_empty() && !self.no_git {
p_println!(!self.quiet => "Updating dependencies in {}", libs.display());
git.submodule_update(false, false, false, Some(&libs))?;
// recursively fetch all submodules (without fetching latest)
git.submodule_update(false, false, false, true, Some(&libs))?;
}
fs::create_dir_all(&libs)?;

Expand Down Expand Up @@ -303,8 +304,8 @@ impl Installer<'_> {
trace!(?dep, url, ?path, "installing git submodule");
self.git.submodule_add(true, url, path)?;

trace!("updating submodule recursively");
self.git.submodule_update(false, false, false, Some(path))
trace!("initializing submodule recursively");
self.git.submodule_update(false, false, false, true, Some(path))
}

fn git_checkout(self, dep: &Dependency, path: &Path, recurse: bool) -> Result<String> {
Expand Down
17 changes: 16 additions & 1 deletion crates/forge/bin/cmd/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,29 @@ pub struct UpdateArgs {
/// Override the up-to-date check.
#[clap(short, long)]
force: bool,

/// Recursively update submodules.
#[clap(short, long)]
recursive: bool,
}
impl_figment_convert_basic!(UpdateArgs);

impl UpdateArgs {
pub fn run(self) -> Result<()> {
let config = self.try_load_config_emit_warnings()?;
let (root, paths) = dependencies_paths(&self.dependencies, &config)?;
Git::new(&root).submodule_update(self.force, true, false, paths)
// fetch the latest changes for each submodule (recursively if flag is set)
let git = Git::new(&root);
if self.recursive {
// update submodules recursively
git.submodule_update(self.force, true, false, true, paths)
} else {
// update root submodules
git.submodule_update(self.force, true, false, false, paths)?;
// initialize submodules of each submodule recursively (otherwise direct submodule
// dependencies will revert to last commit)
git.submodule_foreach(false, "git submodule update --init --progress --recursive ")
}
}
}

Expand Down

0 comments on commit c1f15c7

Please sign in to comment.