mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-23 09:33:01 +03:00
Do not allow folders without a .git
directory to be added as project (#5099)
This commit is contained in:
parent
21b463982c
commit
4420f5d6be
@ -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"));
|
||||
|
@ -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
|
||||
)
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user