use anyhow::Result;
use crate::cli::UpdateArgs;
use crate::context::Context;
use crate::worktree;
pub fn run(ctx: &Context, args: &UpdateArgs) -> Result<()> {
let repo = ctx.repo()?;
let dim = crate::style::DIM;
let ok = crate::style::OK;
let warn = crate::style::WARN;
if !args.ff_only {
if !ctx.quiet {
let verb = if args.dry_run { "would" } else { "→" };
anstream::eprintln!("{dim}{verb} fetch --all --prune{dim:#}");
}
if !args.dry_run {
worktree::fetch(&repo, ctx.quiet)?;
}
}
if !args.fetch_only {
let trees = worktree::list(&repo)?;
for w in &trees {
if w.bare || w.branch.is_none() {
continue;
}
if args.dry_run {
if !ctx.quiet {
anstream::eprintln!("{dim}would ff {}{dim:#}", w.name);
}
continue;
}
if !ctx.quiet {
anstream::eprint!("{dim}→ ff {} ... {dim:#}", w.name);
}
match worktree::fast_forward(&w.path, ctx.quiet) {
Ok(()) => {
if !ctx.quiet {
anstream::eprintln!("{ok}ok{ok:#}");
}
}
Err(e) => {
if !ctx.quiet {
anstream::eprintln!("{warn}skip{warn:#} ({e})");
}
}
}
}
}
Ok(())
}