Skip to content

Commit

Permalink
git: adding basic function to checkout a branch
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Feb 26, 2024
1 parent 70de208 commit a349bbb
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions coffee_github/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use log::debug;
use tokio::process::Command;

use coffee_lib::errors::CoffeeError;
use coffee_lib::macros::error;
use coffee_lib::url::URL;
use coffee_lib::{commit_id, get_repo_info, sh};
use log::debug;

use coffee_lib::types::response::UpgradeStatus;

Expand Down Expand Up @@ -30,8 +32,6 @@ pub async fn git_upgrade(
branch: &str,
verbose: bool,
) -> Result<UpgradeStatus, CoffeeError> {
use tokio::process::Command;

let repo = git2::Repository::open(path).map_err(|err| error!("{}", err.message()))?;

let (local_commit, _) = get_repo_info!(repo);
Expand All @@ -48,3 +48,25 @@ pub async fn git_upgrade(
Ok(UpgradeStatus::Updated(upstream_commit, date))
}
}

pub async fn git_checkout(

Check warning on line 52 in coffee_github/src/utils.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

function `git_checkout` is never used

Check warning on line 52 in coffee_github/src/utils.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

function `git_checkout` is never used

Check warning on line 52 in coffee_github/src/utils.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

function `git_checkout` is never used

Check warning on line 52 in coffee_github/src/utils.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

function `git_checkout` is never used

Check warning on line 52 in coffee_github/src/utils.rs

View workflow job for this annotation

GitHub Actions / Build (stable)

function `git_checkout` is never used

Check warning on line 52 in coffee_github/src/utils.rs

View workflow job for this annotation

GitHub Actions / Build (stable)

function `git_checkout` is never used
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);

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 (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))
}
}

0 comments on commit a349bbb

Please sign in to comment.