Commit

Author:

Hash:

Timestamp:

+16 -14 +/-1 browse

Kevin Schoon [me@kevinschoon.com]

acd2b9887e3ef9897fc34666c3188c9fd3047297

Fri, 18 Jul 2025 09:05:11 +0000 (1 day ago)

change git wrapper to use PathBuf instead of String
1diff --git a/crates/git/src/wrapper.rs b/crates/git/src/wrapper.rs
2index fd1e292..269d0bb 100644
3--- a/crates/git/src/wrapper.rs
4+++ b/crates/git/src/wrapper.rs
5 @@ -29,7 +29,7 @@ pub struct Selector {
6
7 /// Helpful wrapper around a git repository on the file system.
8 pub struct Wrapper {
9- path: String,
10+ path: PathBuf,
11 repository: Box<Repository>,
12 }
13
14 @@ -37,18 +37,18 @@ impl Wrapper {
15 pub fn new(path: &Path) -> Result<Self, Error> {
16 let repository = Repository::open(path)?;
17 Ok(Wrapper {
18- path: path.to_str().unwrap().to_string(),
19+ path: path.to_path_buf(),
20 repository: Box::new(repository),
21 })
22 }
23
24- pub fn path(&self) -> String {
25- self.path.clone()
26+ pub fn path(&self) -> &Path {
27+ self.path.as_path()
28 }
29
30- fn git_path(&self) -> String {
31- let git_path_regular = self.path.clone() + "/.git";
32- match fs::metadata(Path::new(&git_path_regular)) {
33+ fn git_path(&self) -> PathBuf {
34+ let git_path_regular = self.path.join(Path::new(".git"));
35+ match fs::metadata(&git_path_regular) {
36 Ok(_) => git_path_regular.clone(),
37 Err(_) => self.path.clone(),
38 }
39 @@ -999,16 +999,12 @@ impl Wrapper {
40
41 // since the repository can be bare or regular we need to check since
42 // we're running the git binary directly.
43- let git_path_regular = self.path.clone() + "/.git";
44- let git_path = match fs::metadata(Path::new(&git_path_regular)) {
45- Ok(_) => git_path_regular.clone(),
46- Err(_) => self.path.clone(),
47- };
48+ let git_path_regular = self.git_path();
49
50 let mut command = async_process::Command::new("git");
51 command.args([
52 "--git-dir",
53- &git_path,
54+ &git_path_regular.to_string_lossy(),
55 "archive",
56 "--format=tgz",
57 "--prefix",
58 @@ -1024,10 +1020,16 @@ impl Wrapper {
59 }
60
61 /// verify the signature of the given commit
62+ /// TODO: Can this be done with libgit2?
63 pub fn verify(&self, id: &str) -> Result<Option<bool>, Error> {
64 let git_path = self.git_path();
65 let mut command = Command::new("git");
66- command.args(["--git-dir", &git_path, "verify-commit", id]);
67+ command.args([
68+ "--git-dir",
69+ &git_path.to_string_lossy(),
70+ "verify-commit",
71+ id,
72+ ]);
73 command.stderr(Stdio::piped());
74 let output = command.spawn()?.wait()?;
75 Ok(Some(output.success()))