]> quire.kejadlen.dev Git - quire.git/commitdiff
Extract Repo::git helper for running commands in bare repos
authorAlpha Chen <alpha@kejadlen.dev>
Sun, 26 Apr 2026 19:09:18 +0000 (12:09 -0700)
committerAlpha Chen <alpha@kejadlen.dev>
Mon, 27 Apr 2026 01:34:36 +0000 (18:34 -0700)
Returns a Command with current_dir set so callers can chain .status(),
.output(), or anything else without repeating the setup.

Assisted-by: GLM-5.1 via pi
src/quire.rs

index 3935aaf95498170adcf087498fa67f60210eba88..b94ac5fa5f2e4f8930fd4c7a697d81af94f37d7b 100644 (file)
@@ -23,7 +23,6 @@ pub struct GithubConfig {
 /// Loaded from `HEAD:.quire/config.fnl` in the bare repo via `git show`.
 #[derive(serde::Deserialize, Debug, Default, PartialEq)]
 pub struct RepoConfig {
-    #[serde(default)]
     pub mirror: Option<MirrorConfig>,
 }
 
@@ -48,6 +47,16 @@ impl Repo {
         self.path.is_dir()
     }
 
+    /// Start a git command rooted in this bare repo.
+    ///
+    /// Returns a `Command` with `current_dir` set. The caller decides
+    /// `.status()`, `.output()`, or anything else.
+    fn git(&self, args: &[&str]) -> std::process::Command {
+        let mut cmd = std::process::Command::new("git");
+        cmd.args(args).current_dir(&self.path);
+        cmd
+    }
+
     /// Load per-repo config from `HEAD:.quire/config.fnl`.
     ///
     /// Returns a default (empty) `RepoConfig` when:
@@ -60,9 +69,8 @@ impl Repo {
     pub fn config(&self) -> crate::Result<RepoConfig> {
         // Check whether HEAD exists first — exit code distinguishes this
         // reliably without parsing stderr text.
-        let has_head = std::process::Command::new("git")
-            .args(["rev-parse", "--verify", "HEAD"])
-            .current_dir(&self.path)
+        let has_head = self
+            .git(&["rev-parse", "--verify", "HEAD"])
             .stdout(std::process::Stdio::null())
             .stderr(std::process::Stdio::null())
             .status()
@@ -73,9 +81,8 @@ impl Repo {
             return Ok(RepoConfig::default());
         }
 
-        let output = std::process::Command::new("git")
-            .args(["show", "HEAD:.quire/config.fnl"])
-            .current_dir(&self.path)
+        let output = self
+            .git(&["show", "HEAD:.quire/config.fnl"])
             .output()
             .map_err(crate::Error::Io)?;
 
@@ -129,9 +136,6 @@ impl Quire {
     ///
     /// Caches the result — subsequent calls return the same instance.
     /// Returns a typed error if the file is missing or malformed.
-    /// Load and parse the global Fennel config file.
-    ///
-    /// Returns a typed error if the file is missing or malformed.
     pub fn global_config(&self) -> crate::Result<GlobalConfig> {
         let config_path = self.config_path();
         if !config_path.exists() {