Fix setting for root if there is a root-level repo

This commit is contained in:
2021-11-22 20:48:19 +01:00
parent 77c00cee5f
commit 8ba214d6cf

View File

@@ -303,10 +303,14 @@ fn get_actual_git_directory(path: &Path, is_worktree: bool) -> PathBuf {
} }
} }
fn find_repos(root: &Path) -> Option<Vec<Repo>> { fn find_repos(root: &Path) -> Option<(Vec<Repo>, bool)> {
let mut repos: Vec<Repo> = Vec::new(); let mut repos: Vec<Repo> = Vec::new();
let mut repo_in_root = false;
for (path, is_worktree) in find_repos_without_details(root).unwrap() { for (path, is_worktree) in find_repos_without_details(root).unwrap() {
if path == root {
repo_in_root = true;
}
let repo = match open_repo(&path, is_worktree) { let repo = match open_repo(&path, is_worktree) {
Ok(r) => r, Ok(r) => r,
Err(e) => { Err(e) => {
@@ -406,16 +410,25 @@ fn find_repos(root: &Path) -> Option<Vec<Repo>> {
worktree_setup: is_worktree, worktree_setup: is_worktree,
}); });
} }
Some(repos) Some((repos, repo_in_root))
} }
fn find_in_tree(path: &Path) -> Option<Tree> { fn find_in_tree(path: &Path) -> Option<Tree> {
let repos: Vec<Repo> = match find_repos(path) { let (repos, repo_in_root): (Vec<Repo>, bool) = match find_repos(path) {
Some(vec) => vec, Some((vec, repo_in_root)) => (vec, repo_in_root),
None => Vec::new(), None => (Vec::new(), false),
}; };
let mut root = path.to_path_buf(); let mut root = path.to_path_buf();
if repo_in_root {
root = match root.parent() {
Some(root) => root.to_path_buf(),
None => {
print_error("Cannot detect root directory. Are you working in /?");
process::exit(1);
}
}
}
let home = env_home(); let home = env_home();
if root.starts_with(&home) { if root.starts_with(&home) {
// The tilde is not handled differently, it's just a normal path component for `Path`. // The tilde is not handled differently, it's just a normal path component for `Path`.