docker_pose/
git.rs

1use crate::Verbosity;
2use crate::{cmd_call, cmd_call_to_string};
3
4use std::env::var;
5use std::io;
6use std::process::Output;
7
8pub struct GitCommand {
9    pub git_bin: String,
10    pub verbosity: Verbosity,
11}
12
13impl GitCommand {
14    pub fn new(verbosity: Verbosity) -> Self {
15        Self {
16            git_bin: var("GIT_BIN").unwrap_or("git".to_string()),
17            verbosity,
18        }
19    }
20
21    pub fn call_to_string(&self, args: &[&str]) -> String {
22        cmd_call_to_string(&self.git_bin, args)
23    }
24
25    pub fn call_cmd(
26        &self,
27        args: &[&str],
28        output_stdout: bool,
29        output_stderr: bool,
30    ) -> io::Result<Output> {
31        cmd_call(
32            &self.git_bin,
33            args,
34            output_stdout,
35            output_stderr,
36            &self.verbosity,
37        )
38    }
39
40    pub fn get_current_branch(&self) -> io::Result<Output> {
41        self.call_cmd(&["rev-parse", "--abbrev-ref", "HEAD"], false, false)
42    }
43}