git: Use environment from login shell to search for system git binary, and prefer it to the bundled binary (#39302)

Closes #38571

Release Notes:

- git: Fixed git features not working when git was installed in an
unusual location.

---------

Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
This commit is contained in:
Cole Miller
2025-10-02 14:22:10 -04:00
committed by GitHub
co-authored by Lukas Wirth
parent dbd8efe129
commit af630be7ca
5 changed files with 112 additions and 54 deletions
+4 -1
View File
@@ -4607,9 +4607,12 @@ impl Repository {
log::error!("failed to get working directory environment for repository {work_directory_abs_path:?}");
HashMap::default()
});
let search_paths = environment.get("PATH").map(|val| val.to_owned());
let backend = cx
.background_spawn(async move {
fs.open_repo(&dot_git_abs_path)
let system_git_binary_path = search_paths.and_then(|search_paths| which::which_in("git", Some(search_paths), &work_directory_abs_path).ok())
.or_else(|| which::which("git").ok());
fs.open_repo(&dot_git_abs_path, system_git_binary_path.as_deref())
.with_context(|| format!("opening repository at {dot_git_abs_path:?}"))
})
.await?;
+3 -1
View File
@@ -7797,7 +7797,9 @@ async fn test_staging_random_hunks(
path!("/dir/.git").as_ref(),
&[("file.txt", index_text.clone())],
);
let repo = fs.open_repo(path!("/dir/.git").as_ref()).unwrap();
let repo = fs
.open_repo(path!("/dir/.git").as_ref(), Some("git".as_ref()))
.unwrap();
let project = Project::test(fs.clone(), [path!("/dir").as_ref()], cx).await;
let buffer = project