Skip to content

Commit

Permalink
fixup! core: allow to install a branch
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzopalazzo committed Feb 26, 2024
1 parent 8ef4d35 commit d1159da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
5 changes: 4 additions & 1 deletion coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 3 additions & 9 deletions coffee_github/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,14 @@ pub async fn git_checkout(
path: &str,
branch: &str,
verbose: bool,
) -> Result<UpgradeStatus, CoffeeError> {
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))
}

0 comments on commit d1159da

Please sign in to comment.