Skip to main content

git_proc/
status.rs

1use std::path::Path;
2
3/// Create a new `git status` command builder.
4#[must_use]
5pub fn new() -> Status<'static> {
6    Status::new()
7}
8
9/// Builder for `git status` command.
10///
11/// See `git status --help` for full documentation.
12#[derive(Debug)]
13pub struct Status<'a> {
14    repo_path: Option<&'a Path>,
15    porcelain: bool,
16}
17
18crate::impl_repo_path!(Status);
19crate::impl_porcelain!(Status);
20
21impl<'a> Status<'a> {
22    #[must_use]
23    fn new() -> Self {
24        Self {
25            repo_path: None,
26            porcelain: false,
27        }
28    }
29}
30
31impl Default for Status<'_> {
32    fn default() -> Self {
33        Self::new()
34    }
35}
36
37impl crate::Build for Status<'_> {
38    fn build(self) -> cmd_proc::Command {
39        crate::base_command(self.repo_path)
40            .argument("status")
41            .optional_flag(self.porcelain, "--porcelain")
42    }
43}
44
45#[cfg(feature = "test-utils")]
46impl Status<'_> {
47    /// Compare the built command with another command using debug representation.
48    pub fn test_eq(&self, other: &cmd_proc::Command) {
49        let command = crate::Build::build(Self {
50            repo_path: self.repo_path,
51            porcelain: self.porcelain,
52        });
53        command.test_eq(other);
54    }
55}
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60    use crate::Build;
61
62    #[tokio::test]
63    async fn test_status() {
64        let output = Status::new()
65            .build()
66            .capture_stdout()
67            .string()
68            .await
69            .unwrap();
70        // Just verify it runs without error
71        let _ = output;
72    }
73
74    #[tokio::test]
75    async fn test_status_porcelain() {
76        let output = Status::new()
77            .porcelain()
78            .build()
79            .capture_stdout()
80            .string()
81            .await
82            .unwrap();
83        // Porcelain output is empty if repo is clean
84        let _ = output;
85    }
86}