diff --git a/cli/src/cmd/forge/install.rs b/cli/src/cmd/forge/install.rs index 839295ee93c6..41fcef36cb30 100644 --- a/cli/src/cmd/forge/install.rs +++ b/cli/src/cmd/forge/install.rs @@ -90,6 +90,7 @@ pub(crate) fn install( let target_dir = if let Some(alias) = &dep.alias { alias } else { &dep.name }; let DependencyInstallOpts { no_git, no_commit, quiet } = opts; p_println!(!quiet => "Installing {} in {:?}, (url: {}, tag: {:?})", dep.name, &libs.join(&target_dir), dep.url, dep.tag); + check_tag(&dep)?; if no_git { install_as_folder(&dep, &libs)?; } else { @@ -101,6 +102,21 @@ pub(crate) fn install( Ok(()) } +/// make sure tag exists on the remote repository +fn check_tag(dep: &Dependency) -> eyre::Result<()> { + if let Some(ref tag) = dep.tag { + let output = Command::new("git") + .args(&["ls-remote", &dep.url, tag]) + .stdout(Stdio::piped()) + .output()?; + let stdout = String::from_utf8_lossy(&output.stdout); + if !stdout.contains(tag) { + eyre::bail!("tag/branch/commit \"{}\" does not exists", tag) + } + } + Ok(()) +} + /// installs the dependency as an ordinary folder instead of a submodule fn install_as_folder(dep: &Dependency, libs: &Path) -> eyre::Result<()> { let target_dir = if let Some(alias) = &dep.alias { alias } else { &dep.name };