mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
switch to multiprogress for git pull
This commit is contained in:
parent
373ce0f3fd
commit
8771e7dc5f
1 changed files with 25 additions and 9 deletions
34
src/git.rs
34
src/git.rs
|
|
@ -2,11 +2,13 @@ use crate::config::HazeConfig;
|
|||
use crate::Result;
|
||||
use git2::build::CheckoutBuilder;
|
||||
use git2::{Branch, BranchType, Repository, RepositoryState};
|
||||
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
||||
use miette::{Context, IntoDiagnostic};
|
||||
use std::fs::read_dir;
|
||||
use std::iter::once;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::time::Duration;
|
||||
|
||||
fn find_app_repos(config: &HazeConfig) -> Result<impl Iterator<Item = PathBuf>> {
|
||||
let apps_dirs = once(config.sources_root.as_path().join("apps"))
|
||||
|
|
@ -83,6 +85,9 @@ const GIT_BINARY: &str = match option_env!("GIT_BINARY") {
|
|||
pub fn pull_all(config: &HazeConfig) -> Result<()> {
|
||||
let (max_app, max_branch) = longest_app_branch(config)?;
|
||||
|
||||
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)
|
||||
|
|
@ -90,17 +95,26 @@ pub fn pull_all(config: &HazeConfig) -> Result<()> {
|
|||
.wrap_err_with(|| format!("Failed to open repository {}", app_dir.display()))?;
|
||||
let branch_name = current_branch_name(&repo).unwrap_or("unknown".into());
|
||||
|
||||
print!(
|
||||
"{app_name:<app_width$} - {branch_name:<branch_width$}",
|
||||
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);
|
||||
|
||||
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 {
|
||||
println!(": repository not clean ❌");
|
||||
bar.set_message(msg("repository not clean ❌"));
|
||||
bar.finish();
|
||||
continue;
|
||||
}
|
||||
|
||||
bar.set_message(msg(""));
|
||||
|
||||
let output = Command::new(GIT_BINARY)
|
||||
.arg("pull")
|
||||
.current_dir(&app_dir)
|
||||
|
|
@ -109,11 +123,13 @@ pub fn pull_all(config: &HazeConfig) -> Result<()> {
|
|||
.wrap_err_with(|| format!("Failed to run git pull for {}", app_dir.display()))?;
|
||||
|
||||
if output.status.success() {
|
||||
println!(" ✓");
|
||||
bar.set_message(msg(" ✓"));
|
||||
} else {
|
||||
println!(" ❌");
|
||||
eprintln!("{}", String::from_utf8_lossy(&output.stderr))
|
||||
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