From 845eb4ce010988bf99e21aaf3b09d7bac144f652 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 18 Jan 2024 00:19:38 +0900 Subject: [PATCH] git_backend: when running "git gc", chdir instead of specifying it by GIT_DIR Hopefully this will be more reliable on Windows where path/environment stuff is messy. --- lib/src/git_backend.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/src/git_backend.rs b/lib/src/git_backend.rs index 677b684ca..12d4bc5ae 100644 --- a/lib/src/git_backend.rs +++ b/lib/src/git_backend.rs @@ -19,7 +19,7 @@ use std::collections::HashSet; use std::fmt::{Debug, Error, Formatter}; use std::io::{Cursor, Read}; use std::path::{Path, PathBuf}; -use std::process::ExitStatus; +use std::process::{Command, ExitStatus}; use std::sync::{Arc, Mutex, MutexGuard}; use std::{fs, io, str}; @@ -606,9 +606,12 @@ fn to_no_gc_ref_update(id: &CommitId) -> gix::refs::transaction::RefEdit { } fn run_git_gc(git_dir: &Path) -> Result<(), GitGcError> { - let mut git = std::process::Command::new("git"); - git.env("GIT_DIR", git_dir); - git.args(["gc"]); + let mut git = Command::new("git"); + git.arg("--git-dir=."); // turn off discovery + git.arg("gc"); + // Don't specify it by GIT_DIR/--git-dir. On Windows, the "\\?\" path might + // not be supported by git. + git.current_dir(git_dir); // TODO: pass output to UI layer instead of printing directly here let status = git.status().map_err(GitGcError::GcCommand)?; if !status.success() {