upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/git.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-01-23 00:00:00 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-01-23 00:00:00 +0000
commit7799b0edd16b0c97eb58ba2de62be27134a76122 (patch)
tree1cacb8026e251f51279b6a6be4f57a3cc9b978d2 /src/git.rs
parentc543b2f25b6893e5dce6111bc12d9812099251ba (diff)
feat(prs-list): check for clean repo
before checking out PR branch add confirm prompt before checking out branch and applying changes
Diffstat (limited to 'src/git.rs')
-rw-r--r--src/git.rs14
1 files changed, 13 insertions, 1 deletions
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;
3use std::{env::current_dir, path::Path}; 3use std::{env::current_dir, path::Path};
4 4
5use anyhow::{bail, Context, Result}; 5use anyhow::{bail, Context, Result};
6use git2::{Oid, Revwalk}; 6use git2::{DiffOptions, Oid, Revwalk};
7use nostr::prelude::{sha1::Hash as Sha1Hash, Hash}; 7use nostr::prelude::{sha1::Hash as Sha1Hash, Hash};
8 8
9use crate::sub_commands::prs::list::tag_value; 9use crate::sub_commands::prs::list::tag_value;
@@ -52,6 +52,8 @@ pub trait RepoActions {
52 base_commit: &Sha1Hash, 52 base_commit: &Sha1Hash,
53 latest_commit: &Sha1Hash, 53 latest_commit: &Sha1Hash,
54 ) -> Result<(Vec<Sha1Hash>, Vec<Sha1Hash>)>; 54 ) -> Result<(Vec<Sha1Hash>, Vec<Sha1Hash>)>;
55 // including (un)staged changes and (un)tracked files
56 fn has_outstanding_changes(&self) -> Result<bool>;
55 fn make_patch_from_commit(&self, commit: &Sha1Hash) -> Result<String>; 57 fn make_patch_from_commit(&self, commit: &Sha1Hash) -> Result<String>;
56 fn extract_commit_pgp_signature(&self, commit: &Sha1Hash) -> Result<String>; 58 fn extract_commit_pgp_signature(&self, commit: &Sha1Hash) -> Result<String>;
57 fn checkout(&self, ref_name: &str) -> Result<Sha1Hash>; 59 fn checkout(&self, ref_name: &str) -> Result<Sha1Hash>;
@@ -242,6 +244,16 @@ impl RepoActions for Repo {
242 .to_owned()) 244 .to_owned())
243 } 245 }
244 246
247 // including (un)staged changes and (un)tracked files
248 fn has_outstanding_changes(&self) -> Result<bool> {
249 let diff = self.git_repo.diff_tree_to_workdir_with_index(
250 Some(&self.git_repo.head()?.peel_to_tree()?),
251 Some(DiffOptions::new().include_untracked(true)),
252 )?;
253
254 Ok(diff.deltas().len().gt(&0))
255 }
256
245 fn get_commits_ahead_behind( 257 fn get_commits_ahead_behind(
246 &self, 258 &self,
247 base_commit: &Sha1Hash, 259 base_commit: &Sha1Hash,