Skip to content

Commit e1147ca

Browse files
committed
feat: add gix commit describe --dirty-suffix
That way a suffix will be added depending on the dirty-state of the repository.
1 parent e027e1f commit e1147ca

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

gitoxide-core/src/repository/commit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub fn describe(
5252
statistics,
5353
max_candidates,
5454
long_format,
55+
dirty_suffix,
5556
}: describe::Options,
5657
) -> Result<()> {
5758
repo.object_cache_size_if_unset(4 * 1024 * 1024);
@@ -80,7 +81,7 @@ pub fn describe(
8081
writeln!(err, "traversed {} commits", resolution.outcome.commits_seen)?;
8182
}
8283

83-
let mut describe_id = resolution.format()?;
84+
let mut describe_id = resolution.format_with_dirty_suffix(dirty_suffix)?;
8485
describe_id.long(long_format);
8586

8687
writeln!(out, "{describe_id}")?;
@@ -97,5 +98,6 @@ pub mod describe {
9798
pub long_format: bool,
9899
pub statistics: bool,
99100
pub max_candidates: usize,
101+
pub dirty_suffix: Option<String>,
100102
}
101103
}

src/plumbing/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ pub fn main() -> Result<()> {
10361036
statistics,
10371037
max_candidates,
10381038
rev_spec,
1039+
dirty_suffix,
10391040
} => prepare_and_run(
10401041
"commit-describe",
10411042
trace,
@@ -1057,6 +1058,7 @@ pub fn main() -> Result<()> {
10571058
statistics,
10581059
max_candidates,
10591060
always,
1061+
dirty_suffix: dirty_suffix.map(|suffix| suffix.unwrap_or_else(|| "dirty".to_string())),
10601062
},
10611063
)
10621064
},

src/plumbing/options/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,10 @@ pub mod commit {
627627
/// If there was no way to describe the commit, fallback to using the abbreviated input revision.
628628
always: bool,
629629

630+
/// Set the suffix to append if the repository is dirty (not counting untracked files).
631+
#[clap(short = 'd', long)]
632+
dirty_suffix: Option<Option<String>>,
633+
630634
/// A specification of the revision to use, or the current `HEAD` if unset.
631635
rev_spec: Option<String>,
632636
},

0 commit comments

Comments
 (0)