diff options
| author | 2026-02-28 11:14:30 -0500 | |
|---|---|---|
| committer | 2026-02-28 11:14:30 -0500 | |
| commit | 4ec76fb35602fa8d44b050a10f68dec79f25e2f6 (patch) | |
| tree | dbabcd44b06562733a5768b01f2e7a75649e57d0 | |
| parent | actually trigger the post-hooks (diff) | |
simplified updating process
| -rw-r--r-- | src/action.rs | 36 | ||||
| -rw-r--r-- | src/util.rs | 10 |
2 files changed, 11 insertions, 35 deletions
diff --git a/src/action.rs b/src/action.rs index d3b9b00..f404494 100644 --- a/src/action.rs +++ b/src/action.rs @@ -7,7 +7,6 @@ use std::path::PathBuf; pub enum Action { Add { url: String }, Update, - Upgrade { packages: Vec<String> }, Remove { packages: Vec<String> }, List, Search { term: String }, @@ -26,10 +25,6 @@ impl Action { Ok(Action::Add { url }) } "update" => Ok(Action::Update), - "upgrade" => { - let packages = args[2..].to_vec(); - Ok(Action::Upgrade { packages }) - } "remove" => { let packages = args[2..].to_vec(); @@ -61,7 +56,6 @@ impl Action { match self { Action::Add { url } => add(url.as_str()), Action::Update => update(), - Action::Upgrade { packages } => upgrade(packages), Action::Remove { packages } => remove(packages), Action::List => list(), Action::Search { term } => Ok(search(term)), @@ -127,33 +121,17 @@ fn update() -> Result<(), String> { } let package_paths = util::collect_packages()?; - util::print_collected_packages(&package_paths, "Packages to update"); - if util::yn_prompt("Proceed with update?") { - for (name, path, _) in package_paths { - util::pull_repo(&path).map_err(|e| format!("failed to update repo: {e}"))?; - println!("{} up to date.", name); + let mut update_pkgs: PackageList = vec![]; + for (name, path, config_path) in package_paths { + if util::pull_repo(&path).map_err(|e| format!("failed to update repo: {e}"))? { + update_pkgs.push((name, path, config_path)); } } - Ok(()) -} - -fn upgrade(packages: Vec<String>) -> Result<(), String> { - if !nix::unistd::geteuid().is_root() { - return Err("upgrade must be run as root".to_string()); - } - - let package_paths: PackageList = if packages.is_empty() { - util::collect_packages()? - } else { - util::collect_named_packages(packages)? - }; - - util::print_collected_packages(&package_paths, "Packages to upgrade"); - - if util::yn_prompt("Proceed with upgrade?") { - for (name, path, cfg_path) in package_paths { + util::print_collected_packages(&update_pkgs, "Packages to update"); + if util::yn_prompt("Proceed with update?") { + for (name, path, cfg_path) in update_pkgs { config::run_config_command(&cfg_path, &path, ConfigCommand::Build)?; config::run_config_command(&cfg_path, &path, ConfigCommand::Install)?; println!("Upgraded {}", name); diff --git a/src/util.rs b/src/util.rs index 7bd2142..9d44e70 100644 --- a/src/util.rs +++ b/src/util.rs @@ -110,7 +110,7 @@ pub fn print_collected_packages(packages: &PackageList, message: &str) { ); } -pub fn pull_repo(path: &Path) -> Result<(), git2::Error> { +pub fn pull_repo(path: &Path) -> Result<bool, git2::Error> { let repo = Repository::open(path)?; let head = repo.head()?; @@ -135,20 +135,18 @@ pub fn pull_repo(path: &Path) -> Result<(), git2::Error> { let (analysis, _pref) = repo.merge_analysis(&[&fetch_commit])?; if analysis.is_fast_forward() { - println!("Fast-forwarding..."); - let refname = format!("refs/heads/{}", branch); let mut reference = repo.find_reference(&refname)?; reference.set_target(fetch_commit.id(), "Fast-Forward")?; repo.set_head(&refname)?; repo.checkout_head(Some(CheckoutBuilder::default().force()))?; + Ok(true) } else if analysis.is_up_to_date() { - println!("Already up to date."); + Ok(false) } else { println!("Non fast-forward merge required (manual merge needed)."); + Ok(false) } - - Ok(()) } pub fn yn_prompt(prompt: &str) -> bool { |
