From 7799b0edd16b0c97eb58ba2de62be27134a76122 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 23 Jan 2024 00:00:00 +0000 Subject: feat(prs-list): check for clean repo before checking out PR branch add confirm prompt before checking out branch and applying changes --- src/git.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/git.rs') diff --git a/src/git.rs b/src/git.rs index 41520c6..e832c23 100644 --- a/src/git.rs +++ b/src/git.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use std::{env::current_dir, path::Path}; use anyhow::{bail, Context, Result}; -use git2::{Oid, Revwalk}; +use git2::{DiffOptions, Oid, Revwalk}; use nostr::prelude::{sha1::Hash as Sha1Hash, Hash}; use crate::sub_commands::prs::list::tag_value; @@ -52,6 +52,8 @@ pub trait RepoActions { base_commit: &Sha1Hash, latest_commit: &Sha1Hash, ) -> Result<(Vec, Vec)>; + // including (un)staged changes and (un)tracked files + fn has_outstanding_changes(&self) -> Result; fn make_patch_from_commit(&self, commit: &Sha1Hash) -> Result; fn extract_commit_pgp_signature(&self, commit: &Sha1Hash) -> Result; fn checkout(&self, ref_name: &str) -> Result; @@ -242,6 +244,16 @@ impl RepoActions for Repo { .to_owned()) } + // including (un)staged changes and (un)tracked files + fn has_outstanding_changes(&self) -> Result { + let diff = self.git_repo.diff_tree_to_workdir_with_index( + Some(&self.git_repo.head()?.peel_to_tree()?), + Some(DiffOptions::new().include_untracked(true)), + )?; + + Ok(diff.deltas().len().gt(&0)) + } + fn get_commits_ahead_behind( &self, base_commit: &Sha1Hash, -- cgit v1.2.3