diff --git a/crates/gitbutler-project/src/controller.rs b/crates/gitbutler-project/src/controller.rs index 353a02c8b..3a0350192 100644 --- a/crates/gitbutler-project/src/controller.rs +++ b/crates/gitbutler-project/src/controller.rs @@ -45,7 +45,16 @@ impl Controller { bail!("can only work in main worktrees"); }; } - Ok(_repo) => {} + Ok(repo) => { + match repo.work_dir() { + None => bail!("Cannot add non-bare repositories without a workdir"), + Some(wd) => { + if !wd.join(".git").is_dir() { + bail!("A git-repository without a `.git` directory cannot currently be added"); + } + } + } + } Err(err) => { return Err(anyhow::Error::from(err)) .context(error::Context::new("must be a Git repository")); diff --git a/crates/gitbutler-project/tests/fixtures/various-repositories.sh b/crates/gitbutler-project/tests/fixtures/various-repositories.sh index f4ff7135a..fade5179f 100644 --- a/crates/gitbutler-project/tests/fixtures/various-repositories.sh +++ b/crates/gitbutler-project/tests/fixtures/various-repositories.sh @@ -13,3 +13,8 @@ git clone simple with-submodule git submodule add ../submodule git commit -m "add submodule" ) + +git clone --bare simple non-bare-without-worktree +(cd non-bare-without-worktree + git config core.bare false +) \ No newline at end of file diff --git a/crates/gitbutler-project/tests/projects/main.rs b/crates/gitbutler-project/tests/projects/main.rs index 0890a67ab..c1f09e48c 100644 --- a/crates/gitbutler-project/tests/projects/main.rs +++ b/crates/gitbutler-project/tests/projects/main.rs @@ -23,18 +23,29 @@ mod add { mod error { use super::*; + use std::path::PathBuf; + + #[test] + #[ignore = "Needs fix in gitoxide so it doesn't assume the parent-dir is the worktree (Git also doesn't do that)"] + fn non_bare_without_worktree() { + let (controller, _tmp) = new(); + let root = repo_path_at("non-bare-without-worktree"); + let err = controller.add(root).unwrap_err(); + assert_eq!( + err.to_string(), + "Cannot add non-bare repositories without a workdir" + ); + } #[test] fn submodule() { let (controller, _tmp) = new(); - let root = gitbutler_testsupport::gix_testtools::scripted_fixture_read_only( - "various-repositories.sh", - ) - .unwrap() - .join("with-submodule") - .join("submodule"); + let root = repo_path_at("with-submodule").join("submodule"); let err = controller.add(root).unwrap_err(); - assert_eq!(err.to_string(), "TBD"); + assert_eq!( + err.to_string(), + "A git-repository without a `.git` directory cannot currently be added" + ); } #[test] @@ -126,6 +137,14 @@ mod add { ) .unwrap() } + + fn repo_path_at(name: &str) -> PathBuf { + gitbutler_testsupport::gix_testtools::scripted_fixture_read_only( + "various-repositories.sh", + ) + .unwrap() + .join(name) + } } }