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