Skip to main content

git_proc/
diff.rs

1/// Create a new `git diff` command builder.
2#[must_use]
3pub fn new() -> Diff<'static> {
4    Diff::new()
5}
6
7/// Builder for `git diff` command.
8///
9/// See `git diff --help` for full documentation.
10#[derive(Debug)]
11pub struct Diff<'a> {
12    base: crate::RepoBase<'a>,
13    exit_code: bool,
14}
15
16crate::impl_repo_base!(Diff);
17
18impl<'a> Diff<'a> {
19    #[must_use]
20    fn new() -> Self {
21        Self {
22            base: crate::RepoBase::default(),
23            exit_code: false,
24        }
25    }
26
27    /// Make the program exit with codes similar to diff(1).
28    ///
29    /// Exits with 1 if there were differences and 0 means no differences.
30    ///
31    /// Corresponds to `--exit-code`.
32    #[must_use]
33    pub fn exit_code(mut self) -> Self {
34        self.exit_code = true;
35        self
36    }
37}
38
39impl Default for Diff<'_> {
40    fn default() -> Self {
41        Self::new()
42    }
43}
44
45impl crate::Build for Diff<'_> {
46    fn build(self) -> Result<cmd_proc::Command, crate::EnvError> {
47        Ok(self
48            .base
49            .command()?
50            .argument("diff")
51            .optional_flag(self.exit_code, "--exit-code"))
52    }
53}