1use std::path::Path;
6
7use crate::execute::{Command, CommandBuilder};
8
9pub struct Fsck<'a> {
11 pub config_path: &'a Path,
13 pub connectivity_only: bool,
15 pub no_dangling: bool,
17}
18
19impl CommandBuilder for Fsck<'_> {
20 fn build(&self, current_dir: &Path) -> tokio::process::Command {
21 let mut cmd = Command::new("git");
22 cmd.current_dir(current_dir);
23 cmd.envs([(
24 crate::git_config::GIT_CONFIG_GLOBAL,
25 self.config_path.to_string_lossy().as_ref(),
26 )]);
27 let mut args = vec!["fsck", "--no-progress"];
28 if self.connectivity_only {
29 args.push("--connectivity-only");
30 }
31 if self.no_dangling {
32 args.push("--no-dangling");
33 }
34 cmd.args(args);
35 cmd
36 }
37}
38
39#[cfg(test)]
40mod tests {
41 use crate::test_server::{TestBuilder, DEFAULT_WORKSPACE};
42
43 use super::*;
44
45 #[tokio::test]
46 pub async fn run_git_fsck_bare() {
47 let test = TestBuilder::default().workspace(DEFAULT_WORKSPACE);
48 let fsck = Fsck {
49 config_path: Path::new("/dev/null"),
50 connectivity_only: false,
51 no_dangling: false,
52 };
53 fsck.build(test.workspace.unwrap().repository_path().as_path())
54 .output()
55 .await
56 .unwrap();
57 }
58}