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