diff --git a/tools/cargo-check-external-types/Cargo.lock b/tools/cargo-check-external-types/Cargo.lock index 5eeb438344cbd2fa2ae2d28b8ffe96d8bd680faa..c034a93937cb5b84ae658970eabc6dac72444188 100644 --- a/tools/cargo-check-external-types/Cargo.lock +++ b/tools/cargo-check-external-types/Cargo.lock @@ -51,7 +51,7 @@ dependencies = [ [[package]] name = "cargo-check-external-types" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "cargo_metadata", diff --git a/tools/smithy-rs-tool-common/Cargo.toml b/tools/smithy-rs-tool-common/Cargo.toml index c370a6e4031131d038db276837bbb5e9397f32d4..e3b6e870603755e8c2ee07caa41e979ff86b692f 100644 --- a/tools/smithy-rs-tool-common/Cargo.toml +++ b/tools/smithy-rs-tool-common/Cargo.toml @@ -27,3 +27,6 @@ serde_json = "1" tokio = { version = "1", features = ["rt", "macros"], optional = true } toml = { version = "0.5.8", features = ["preserve_order"] } tracing = "0.1" + +[dev-dependencies] +tempfile = "3.3.0" diff --git a/tools/smithy-rs-tool-common/src/git.rs b/tools/smithy-rs-tool-common/src/git.rs index 22b670e181bb1067b841ccd422062ce6623118ea..b22543f0ab5ceea41f6c5b20d9b0d450a4ac7478 100644 --- a/tools/smithy-rs-tool-common/src/git.rs +++ b/tools/smithy-rs-tool-common/src/git.rs @@ -151,7 +151,7 @@ pub struct GitCLI { impl GitCLI { pub fn new(repo_path: &Path) -> Result { - if !repo_path.join(".git").is_dir() { + if !repo_path.join(".git").exists() { bail!("{:?} is not a git repository", repo_path); } Ok(Self { @@ -429,7 +429,8 @@ fn log_command(command: Command) -> Command { #[cfg(test)] mod tests { use super::*; - use std::env; + use std::{env, fs}; + use tempfile::TempDir; fn bin_path(script: &'static str) -> PathBuf { env::current_dir() @@ -616,4 +617,26 @@ mod tests { .squash_merge("some-dev", "some-email@example.com", "test-branch-name") .expect("successful invocation"); } + + #[test] + fn repository_root_check() { + let tmp_dir = TempDir::new().unwrap(); + GitCLI::new(tmp_dir.path()) + .err() + .expect("repository root check should fail"); + + fs::create_dir(tmp_dir.path().join(".git")).unwrap(); + GitCLI::new(tmp_dir.path()).expect("repository root check should succeed"); + } + + #[test] + fn repository_root_check_works_for_git_submodules() { + let tmp_dir = TempDir::new().unwrap(); + GitCLI::new(tmp_dir.path()) + .err() + .expect("repository root check should fail"); + + fs::write(tmp_dir.path().join(".git"), "gitdir: some/fake/path").unwrap(); + GitCLI::new(tmp_dir.path()).expect("repository root check should succeed"); + } }