Unverified Commit 275a6f8a authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Fix git root check for submodules (#1640)

parent 7731b3f1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ dependencies = [

[[package]]
name = "cargo-check-external-types"
version = "0.1.0"
version = "0.1.1"
dependencies = [
 "anyhow",
 "cargo_metadata",
+3 −0
Original line number Diff line number Diff line
@@ -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"
+25 −2
Original line number Diff line number Diff line
@@ -151,7 +151,7 @@ pub struct GitCLI {

impl GitCLI {
    pub fn new(repo_path: &Path) -> Result<Self> {
        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");
    }
}