1use std::process::Command;
7
8use crate::error::ReviseResult;
9
10pub trait GitRepository {
11 fn git_repo() -> ReviseResult<String> {
12 let output = Command::new("git")
13 .args(["rev-parse", "--show-toplevel"])
14 .output()?;
15
16 if !output.status.success() {
17 return Err(anyhow::anyhow!(
18 "Failed to get git repository: {}",
19 String::from_utf8_lossy(&output.stderr)
20 ));
21 }
22
23 Ok(String::from_utf8(output.stdout)?.trim().to_string())
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30
31 #[test]
32 #[ignore]
33 fn test_git_repo() {
34 struct GitRepoImpl;
35 impl GitRepository for GitRepoImpl {}
36 let repo = GitRepoImpl::git_repo().unwrap();
37 println!("Git repository: {repo}");
38 }
39}