mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 09:04:12 +02:00
parent
8771e7dc5f
commit
b977cd9dfa
3 changed files with 103 additions and 40 deletions
92
src/git.rs
92
src/git.rs
|
|
@ -4,6 +4,8 @@ use git2::build::CheckoutBuilder;
|
|||
use git2::{Branch, BranchType, Repository, RepositoryState};
|
||||
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
||||
use miette::{Context, IntoDiagnostic};
|
||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
||||
use rayon::ThreadPoolBuilder;
|
||||
use std::fs::read_dir;
|
||||
use std::iter::once;
|
||||
use std::path::PathBuf;
|
||||
|
|
@ -88,49 +90,63 @@ pub fn pull_all(config: &HazeConfig) -> Result<()> {
|
|||
let progress = MultiProgress::new();
|
||||
let pull_style = ProgressStyle::with_template("{spinner:.green} {msg}").unwrap();
|
||||
|
||||
for app_dir in find_app_repos(config)? {
|
||||
let app_name = app_dir.file_name().unwrap().to_string_lossy();
|
||||
let repo = Repository::init(&app_dir)
|
||||
.into_diagnostic()
|
||||
.wrap_err_with(|| format!("Failed to open repository {}", app_dir.display()))?;
|
||||
let branch_name = current_branch_name(&repo).unwrap_or("unknown".into());
|
||||
let pool = ThreadPoolBuilder::new()
|
||||
.num_threads(8)
|
||||
.build()
|
||||
.into_diagnostic()?;
|
||||
let repos = find_app_repos(config)?.collect::<Vec<_>>();
|
||||
|
||||
let bar = ProgressBar::new_spinner().with_style(pull_style.clone());
|
||||
bar.enable_steady_tick(Duration::from_millis(100));
|
||||
let bar = progress.add(bar);
|
||||
pool.install(|| {
|
||||
repos.par_iter().for_each(|app_dir| {
|
||||
let app_name = app_dir.file_name().unwrap().to_string_lossy();
|
||||
let Ok(repo) = Repository::init(&app_dir) else {
|
||||
return;
|
||||
};
|
||||
let branch_name = current_branch_name(&repo).unwrap_or("unknown".into());
|
||||
|
||||
let msg = |state: &str| {
|
||||
format!(
|
||||
"{app_name:<app_width$} - {branch_name:<branch_width$}{state}",
|
||||
app_width = max_app,
|
||||
branch_width = max_branch
|
||||
)
|
||||
};
|
||||
let bar = ProgressBar::new_spinner().with_style(pull_style.clone());
|
||||
bar.enable_steady_tick(Duration::from_millis(100));
|
||||
let bar = progress.add(bar);
|
||||
|
||||
if repo.state() != RepositoryState::Clean {
|
||||
bar.set_message(msg("repository not clean ❌"));
|
||||
let msg = |state: &str| {
|
||||
format!(
|
||||
"{app_name:<app_width$} - {branch_name:<branch_width$}{state}",
|
||||
app_width = max_app,
|
||||
branch_width = max_branch
|
||||
)
|
||||
};
|
||||
|
||||
if repo.state() != RepositoryState::Clean {
|
||||
bar.set_message(msg(" ⨯ repository not clean"));
|
||||
bar.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
bar.set_message(msg(""));
|
||||
|
||||
let output = match Command::new(GIT_BINARY)
|
||||
.arg("pull")
|
||||
.current_dir(&app_dir)
|
||||
.output()
|
||||
{
|
||||
Ok(output) => output,
|
||||
Err(error) => {
|
||||
bar.set_message(msg(&format!(" ⨯ {error}")));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if output.status.success() {
|
||||
bar.set_message(msg(" ✓"));
|
||||
} else {
|
||||
let err = String::from_utf8_lossy(&output.stderr);
|
||||
let err_line = err.lines().next().unwrap();
|
||||
bar.set_message(msg(&format!(" ⨯ {err_line}")));
|
||||
}
|
||||
bar.finish();
|
||||
continue;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
bar.set_message(msg(""));
|
||||
|
||||
let output = Command::new(GIT_BINARY)
|
||||
.arg("pull")
|
||||
.current_dir(&app_dir)
|
||||
.output()
|
||||
.into_diagnostic()
|
||||
.wrap_err_with(|| format!("Failed to run git pull for {}", app_dir.display()))?;
|
||||
|
||||
if output.status.success() {
|
||||
bar.set_message(msg(" ✓"));
|
||||
} else {
|
||||
let err = String::from_utf8_lossy(&output.stderr);
|
||||
let err_line = err.lines().next().unwrap();
|
||||
bar.set_message(msg(&format!(" ❌ {err_line}")));
|
||||
}
|
||||
bar.finish();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue