gitoxide_core/repository/
dirty.rs1use crate::OutputFormat;
2use anyhow::bail;
3
4pub enum Mode {
5 IsClean,
6 IsDirty,
7}
8
9pub fn check(
10 repo: gix::Repository,
11 mode: Mode,
12 out: &mut dyn std::io::Write,
13 format: OutputFormat,
14) -> anyhow::Result<()> {
15 if format != OutputFormat::Human {
16 bail!("JSON output isn't implemented yet");
17 }
18 let is_dirty = repo.is_dirty()?;
19 let res = match (is_dirty, mode) {
20 (false, Mode::IsClean) => Ok("The repository is clean"),
21 (true, Mode::IsClean) => Err("The repository has changes"),
22 (false, Mode::IsDirty) => Err("The repository is clean"),
23 (true, Mode::IsDirty) => Ok("The repository has changes"),
24 };
25
26 let suffix = "(not counting untracked files)";
27 match res {
28 Ok(msg) => writeln!(out, "{msg} {suffix}")?,
29 Err(msg) => bail!("{msg} {suffix}"),
30 }
31 Ok(())
32}