From 58231b418fa39ea122ef41bb7691289f5b0be855 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 9 Mar 2024 12:35:06 +0100 Subject: [PATCH] feat: add `gix commit describe --dirty-suffix` That way a suffix will be added depending on the dirty-state of the repository. --- gitoxide-core/src/repository/commit.rs | 4 +++- src/plumbing/main.rs | 2 ++ src/plumbing/options/mod.rs | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/gitoxide-core/src/repository/commit.rs b/gitoxide-core/src/repository/commit.rs index 17ce99e5f3c..e0070dc2ae3 100644 --- a/gitoxide-core/src/repository/commit.rs +++ b/gitoxide-core/src/repository/commit.rs @@ -52,6 +52,7 @@ pub fn describe( statistics, max_candidates, long_format, + dirty_suffix, }: describe::Options, ) -> Result<()> { repo.object_cache_size_if_unset(4 * 1024 * 1024); @@ -80,7 +81,7 @@ pub fn describe( writeln!(err, "traversed {} commits", resolution.outcome.commits_seen)?; } - let mut describe_id = resolution.format()?; + let mut describe_id = resolution.format_with_dirty_suffix(dirty_suffix)?; describe_id.long(long_format); writeln!(out, "{describe_id}")?; @@ -97,5 +98,6 @@ pub mod describe { pub long_format: bool, pub statistics: bool, pub max_candidates: usize, + pub dirty_suffix: Option, } } diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index aeb589c584f..658fa4bc21b 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -1036,6 +1036,7 @@ pub fn main() -> Result<()> { statistics, max_candidates, rev_spec, + dirty_suffix, } => prepare_and_run( "commit-describe", trace, @@ -1057,6 +1058,7 @@ pub fn main() -> Result<()> { statistics, max_candidates, always, + dirty_suffix: dirty_suffix.map(|suffix| suffix.unwrap_or_else(|| "dirty".to_string())), }, ) }, diff --git a/src/plumbing/options/mod.rs b/src/plumbing/options/mod.rs index 690ea56ecaa..e4aff7ad5cb 100644 --- a/src/plumbing/options/mod.rs +++ b/src/plumbing/options/mod.rs @@ -627,6 +627,10 @@ pub mod commit { /// If there was no way to describe the commit, fallback to using the abbreviated input revision. always: bool, + /// Set the suffix to append if the repository is dirty (not counting untracked files). + #[clap(short = 'd', long)] + dirty_suffix: Option>, + /// A specification of the revision to use, or the current `HEAD` if unset. rev_spec: Option, },