Skip to main content

git_proc/
show.rs

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