From d1159dafe8ff7669e19fba841cd4fa2ff7d789be Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Mon, 26 Feb 2024 23:10:30 +0100 Subject: [PATCH] fixup! core: allow to install a branch --- coffee_core/src/coffee.rs | 5 ++++- coffee_github/src/utils.rs | 12 +++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index e24874c..b982840 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -288,7 +288,10 @@ impl PluginManager for CoffeeManager { plugin.exec_path = new_exec_path; if let Some(branch) = branch { - let _ = git_checkout(&plugin.root_path, &branch, verbose).await?; + // FIXME: Where we store the date? how we manage it? + let (commit, _) = + git_checkout(&plugin.root_path, &branch, verbose).await?; + plugin.commit = Some(commit); } log::debug!("plugin: {:?}", plugin); diff --git a/coffee_github/src/utils.rs b/coffee_github/src/utils.rs index ac90d3b..d578e74 100644 --- a/coffee_github/src/utils.rs +++ b/coffee_github/src/utils.rs @@ -53,20 +53,14 @@ pub async fn git_checkout( path: &str, branch: &str, verbose: bool, -) -> Result { - let repo = git2::Repository::open(path).map_err(|err| error!("{}", err.message()))?; - let (local_commit, _) = get_repo_info!(repo); - +) -> Result<(String, String), CoffeeError> { let mut cmd = format!("git fetch origin\n"); cmd += &format!("git reset --hard\n"); cmd += &format!("git checkout origin/{branch}"); sh!(path, cmd, verbose); + let repo = git2::Repository::open(path).map_err(|err| error!("{}", err.message()))?; let (upstream_commit, date) = get_repo_info!(repo); - if local_commit == upstream_commit { - Ok(UpgradeStatus::UpToDate(upstream_commit, date)) - } else { - Ok(UpgradeStatus::Updated(upstream_commit, date)) - } + Ok((upstream_commit, date)) }