diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-04-10 19:47:52 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-04-10 19:47:52 +0000 |
| commit | 368f0556267b32c5478b7fb68b8a30d42942ee6f (patch) | |
| tree | 7ccc88070c17433dedf3397a87f9c14906c9a57e | |
| parent | 8aef478c6b1e9e3f6ebbad6d57f59f1a84a261ea (diff) | |
fix: pass --git-dir as global git option in check_repo_empty
--git-dir must precede the subcommand; passing it after for-each-ref
caused git to ignore it and check the CWD instead, making every repo
appear empty.
| -rw-r--r-- | src/cleanup_empty_repos.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/cleanup_empty_repos.rs b/src/cleanup_empty_repos.rs index f1d1c3e..8f5492d 100644 --- a/src/cleanup_empty_repos.rs +++ b/src/cleanup_empty_repos.rs | |||
| @@ -344,18 +344,19 @@ pub async fn run(args: &CleanupArgs) -> Result<()> { | |||
| 344 | /// | 344 | /// |
| 345 | /// Returns `(exists, is_empty)`: | 345 | /// Returns `(exists, is_empty)`: |
| 346 | /// - `(false, true)` — path does not exist (treated as empty) | 346 | /// - `(false, true)` — path does not exist (treated as empty) |
| 347 | /// - `(true, true)` — path exists but `git for-each-ref` returns no output | 347 | /// - `(true, true)` — path exists but `git --git-dir=<path> for-each-ref` returns no output |
| 348 | /// - `(true, false)` — path exists and has at least one ref | 348 | /// - `(true, false)` — path exists and has at least one ref |
| 349 | fn check_repo_empty(repo_path: &Path) -> (bool, bool) { | 349 | fn check_repo_empty(repo_path: &Path) -> (bool, bool) { |
| 350 | if !repo_path.exists() { | 350 | if !repo_path.exists() { |
| 351 | return (false, true); | 351 | return (false, true); |
| 352 | } | 352 | } |
| 353 | 353 | ||
| 354 | // Run `git for-each-ref --git-dir=<path>` — empty output means no refs | 354 | // Run `git --git-dir=<path> for-each-ref` — empty output means no refs. |
| 355 | // --git-dir must be a global option before the subcommand, not an argument to for-each-ref. | ||
| 355 | let output = Command::new("git") | 356 | let output = Command::new("git") |
| 356 | .args(["for-each-ref", "--format=%(refname)"]) | ||
| 357 | .arg("--git-dir") | 357 | .arg("--git-dir") |
| 358 | .arg(repo_path) | 358 | .arg(repo_path) |
| 359 | .args(["for-each-ref", "--format=%(refname)"]) | ||
| 359 | .output(); | 360 | .output(); |
| 360 | 361 | ||
| 361 | match output { | 362 | match output { |