git_explore/explore/
git.rs1use crate::PathEx;
2
3use super::*;
4
5pub fn find_git(opt: &ListOption) -> Result<Vec<PathBuf>> {
8 let gits = find_folders(opt.clone()).unwrap();
9
10 let mut paths = Vec::new();
11 gits.iter().for_each(|git| {
12 match git.kind {
13 crate::FilterKind::File => {
14 let file_path = git.workspace.join(".git");
15 let content = file_path.get_content();
17 let key: Vec<_> = content.split(':').collect();
18 if key[0] == "gitdir" {
19 let module_path = git.workspace.join(key[1].trim());
20 if module_path.is_dir() {
21 paths.push(git.workspace.to_owned());
22 }
23 }
24 }
25 crate::FilterKind::Directory => paths.push(git.workspace.to_owned()),
26 }
27 });
28
29 Ok(paths)
30}
31
32#[test]
33fn search_git() {
34 use crate::*;
35 use clap::Parser;
36 let cli = RepoCli::parse_from([KEY_COMMAND, "list", "-d", KEY_BASEPATH]);
37 let ret = if let Some(Command::List(opt)) = cli.command {
39 find_git(&opt)
40 } else {
41 todo!()
42 };
43 insta::assert_debug_snapshot!(ret)
44}