Skip to content

Commit e20c6ed

Browse files
committed
feat: gix submodules list --dirty-suffix for dirty-information
This is a submodule-centric and greatly simplified way of obtaining describe information with dirty-suffix. Note that `status` information is also possible, but it seems hard to display nicely, which this command isn't great at in the first place.
1 parent e1147ca commit e20c6ed

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

gitoxide-core/src/repository/submodule.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ use gix::{commit::describe::SelectRef, prelude::ObjectIdExt, Repository, Submodu
33

44
use crate::OutputFormat;
55

6-
pub fn list(repo: Repository, mut out: impl std::io::Write, format: OutputFormat) -> anyhow::Result<()> {
6+
pub fn list(
7+
repo: Repository,
8+
mut out: impl std::io::Write,
9+
format: OutputFormat,
10+
dirty_suffix: Option<String>,
11+
) -> anyhow::Result<()> {
712
if format != OutputFormat::Human {
813
bail!("Only human output is supported for now")
914
}
@@ -12,12 +17,12 @@ pub fn list(repo: Repository, mut out: impl std::io::Write, format: OutputFormat
1217
return Ok(());
1318
};
1419
for sm in submodules {
15-
print_sm(sm, &mut out)?;
20+
print_sm(sm, dirty_suffix.as_deref(), &mut out)?;
1621
}
1722
Ok(())
1823
}
1924

20-
fn print_sm(sm: Submodule<'_>, out: &mut impl std::io::Write) -> anyhow::Result<()> {
25+
fn print_sm(sm: Submodule<'_>, dirty_suffix: Option<&str>, out: &mut impl std::io::Write) -> anyhow::Result<()> {
2126
let _span = gix::trace::coarse!("print_sm", path = ?sm.path());
2227
let state = sm.state()?;
2328
let mut sm_repo = sm.open()?;
@@ -48,7 +53,10 @@ fn print_sm(sm: Submodule<'_>, out: &mut impl std::io::Write) -> anyhow::Result<
4853
repo.head_commit()?
4954
.describe()
5055
.names(SelectRef::AllRefs)
51-
.format()?
56+
.id_as_fallback(true)
57+
.try_resolve()?
58+
.expect("resolution present if ID can be used as fallback")
59+
.format_with_dirty_suffix(dirty_suffix.map(ToOwned::to_owned))?
5260
.to_string()
5361
}
5462
None => {

src/plumbing/main.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,23 @@ pub fn main() -> Result<()> {
223223
),
224224
Subcommands::Submodule(platform) => match platform
225225
.cmds
226-
.unwrap_or(crate::plumbing::options::submodule::Subcommands::List)
226+
.unwrap_or(crate::plumbing::options::submodule::Subcommands::List { dirty_suffix: None })
227227
{
228-
crate::plumbing::options::submodule::Subcommands::List => prepare_and_run(
228+
crate::plumbing::options::submodule::Subcommands::List { dirty_suffix } => prepare_and_run(
229229
"submodule-list",
230230
trace,
231231
verbose,
232232
progress,
233233
progress_keep_open,
234234
None,
235-
move |_progress, out, _err| core::repository::submodule::list(repository(Mode::Lenient)?, out, format),
235+
move |_progress, out, _err| {
236+
core::repository::submodule::list(
237+
repository(Mode::Lenient)?,
238+
out,
239+
format,
240+
dirty_suffix.map(|suffix| suffix.unwrap_or_else(|| "dirty".to_string())),
241+
)
242+
},
236243
),
237244
},
238245
#[cfg(feature = "gitoxide-core-tools-archive")]

src/plumbing/options/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,11 @@ pub mod submodule {
875875
#[derive(Debug, clap::Subcommand)]
876876
pub enum Subcommands {
877877
/// Print all direct submodules to standard output
878-
List,
878+
List {
879+
/// Set the suffix to append if the repository is dirty (not counting untracked files).
880+
#[clap(short = 'd', long)]
881+
dirty_suffix: Option<Option<String>>,
882+
},
879883
}
880884
}
881885

0 commit comments

Comments
 (0)