Skip to main content

git_proc/
show.rs

1/// Create a new `git show` command builder.
2///
3/// The object can be a commit, tree, blob, or tag reference.
4/// For file contents at a specific revision, use format: `revision:path`
5#[must_use]
6pub fn new(object: &str) -> Show<'_> {
7    Show::new(object)
8}
9
10/// Builder for `git show` command.
11///
12/// See `git show --help` for full documentation.
13#[derive(Debug)]
14pub struct Show<'a> {
15    base: crate::RepoBase<'a>,
16    object: &'a str,
17}
18
19crate::impl_repo_base!(Show);
20
21impl<'a> Show<'a> {
22    #[must_use]
23    fn new(object: &'a str) -> Self {
24        Self {
25            base: crate::RepoBase::default(),
26            object,
27        }
28    }
29}
30
31impl crate::Build for Show<'_> {
32    fn build(self) -> Result<cmd_proc::Command, crate::EnvError> {
33        Ok(self.base.command()?.argument("show").argument(self.object))
34    }
35}
36
37#[cfg(feature = "test-utils")]
38impl Show<'_> {
39    /// Compare the built command with another command using debug representation.
40    pub fn test_eq(&self, other: &cmd_proc::Command) {
41        let command = crate::Build::build(Self {
42            base: self.base,
43            object: self.object,
44        })
45        .unwrap();
46        command.test_eq(other);
47    }
48}