Avoid searching for git repos inside already detected repos (#357)
This commit is contained in:
committed by
GitHub
parent
16efada11b
commit
694c7afc92
26
src/main.rs
26
src/main.rs
@@ -172,37 +172,37 @@ fn run() -> Result<()> {
|
|||||||
if config.should_run(Step::Emacs) {
|
if config.should_run(Step::Emacs) {
|
||||||
if !emacs.is_doom() {
|
if !emacs.is_doom() {
|
||||||
if let Some(directory) = emacs.directory() {
|
if let Some(directory) = emacs.directory() {
|
||||||
git_repos.insert(directory);
|
git_repos.insert_if_repo(directory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
git_repos.insert(base_dirs.home_dir().join(".doom.d"));
|
git_repos.insert_if_repo(base_dirs.home_dir().join(".doom.d"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.should_run(Step::Vim) {
|
if config.should_run(Step::Vim) {
|
||||||
git_repos.insert(base_dirs.home_dir().join(".vim"));
|
git_repos.insert_if_repo(base_dirs.home_dir().join(".vim"));
|
||||||
git_repos.insert(base_dirs.home_dir().join(".config/nvim"));
|
git_repos.insert_if_repo(base_dirs.home_dir().join(".config/nvim"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
git_repos.insert(zsh::zshrc(&base_dirs));
|
git_repos.insert_if_repo(zsh::zshrc(&base_dirs));
|
||||||
git_repos.insert(base_dirs.home_dir().join(".tmux"));
|
git_repos.insert_if_repo(base_dirs.home_dir().join(".tmux"));
|
||||||
git_repos.insert(base_dirs.home_dir().join(".config/fish"));
|
git_repos.insert_if_repo(base_dirs.home_dir().join(".config/fish"));
|
||||||
git_repos.insert(base_dirs.config_dir().join("openbox"));
|
git_repos.insert_if_repo(base_dirs.config_dir().join("openbox"));
|
||||||
git_repos.insert(base_dirs.config_dir().join("bspwm"));
|
git_repos.insert_if_repo(base_dirs.config_dir().join("bspwm"));
|
||||||
git_repos.insert(base_dirs.config_dir().join("i3"));
|
git_repos.insert_if_repo(base_dirs.config_dir().join("i3"));
|
||||||
git_repos.insert(base_dirs.config_dir().join("sway"));
|
git_repos.insert_if_repo(base_dirs.config_dir().join("sway"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
git_repos.insert(
|
git_repos.insert_if_repo(
|
||||||
base_dirs
|
base_dirs
|
||||||
.data_local_dir()
|
.data_local_dir()
|
||||||
.join("Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState"),
|
.join("Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState"),
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(profile) = powershell.profile() {
|
if let Some(profile) = powershell.profile() {
|
||||||
git_repos.insert(profile);
|
git_repos.insert_if_repo(profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::error::{SkipStep, TopgradeError};
|
use crate::error::{SkipStep, TopgradeError};
|
||||||
use crate::executor::{CommandExt, RunType};
|
use crate::executor::{CommandExt, RunType};
|
||||||
use crate::terminal::print_separator;
|
use crate::terminal::print_separator;
|
||||||
use crate::utils::which;
|
use crate::utils::{which, PathExt};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use console::style;
|
use console::style;
|
||||||
use glob::{glob_with, MatchOptions};
|
use glob::{glob_with, MatchOptions};
|
||||||
@@ -221,17 +221,35 @@ impl<'a> Repositories<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert<P: AsRef<Path>>(&mut self, path: P) {
|
pub fn insert_if_repo<P: AsRef<Path>>(&mut self, path: P) -> bool {
|
||||||
if let Some(repo) = self.git.get_repo_root(path) {
|
if let Some(repo) = self.git.get_repo_root(path) {
|
||||||
self.repositories.insert(repo);
|
self.repositories.insert(repo);
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn glob_insert(&mut self, pattern: &str) {
|
pub fn glob_insert(&mut self, pattern: &str) {
|
||||||
if let Ok(glob) = glob_with(pattern, self.glob_match_options) {
|
if let Ok(glob) = glob_with(pattern, self.glob_match_options) {
|
||||||
|
let mut last_git_repo: Option<PathBuf> = None;
|
||||||
for entry in glob {
|
for entry in glob {
|
||||||
match entry {
|
match entry {
|
||||||
Ok(path) => self.insert(path),
|
Ok(path) => {
|
||||||
|
if let Some(last_git_repo) = &last_git_repo {
|
||||||
|
if path.is_descendant_of(&last_git_repo) {
|
||||||
|
debug!(
|
||||||
|
"Skipping {} because it's a decendant of last known repo {}",
|
||||||
|
path.display(),
|
||||||
|
last_git_repo.display()
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if self.insert_if_repo(&path) {
|
||||||
|
last_git_repo = Some(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Error in path {}", e);
|
error!("Error in path {}", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user