Skip to content

Commit

Permalink
use git bash instead of wsl bash
Browse files Browse the repository at this point in the history
  • Loading branch information
hamflx committed Jan 29, 2023
1 parent 48eed05 commit 6480c01
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion asyncgit/src/sync/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct HookPaths {
git: PathBuf,
hook: PathBuf,
pwd: PathBuf,
bash: PathBuf,
}

impl HookPaths {
Expand Down Expand Up @@ -51,10 +52,13 @@ impl HookPaths {
let hook = PathBuf::from_str(hook.as_ref())
.map_err(|_| error::Error::PathString)?;

let git_bash = find_bash_executable();

Ok(Self {
git: git_dir,
hook,
pwd,
bash: git_bash,
})
}

Expand All @@ -70,7 +74,7 @@ impl HookPaths {

log::trace!("run hook '{:?}' in '{:?}'", self.hook, self.pwd);

let output = Command::new("bash")
let output = Command::new(&self.bash)
.args(bash_args)
.current_dir(&self.pwd)
// This call forces Command to handle the Path environment correctly on windows,
Expand Down Expand Up @@ -184,6 +188,29 @@ const fn is_executable(_: &Path) -> bool {
true
}

// Find bash.exe, and avoid finding wsl's bash.exe.
fn find_bash_executable() -> PathBuf {
if cfg!(windows) {
Command::new("where.exe")
.arg("git")
.output()
.ok()
.map(|out| {
PathBuf::from(Into::<String>::into(
String::from_utf8_lossy(&out.stdout),
))
})
.as_deref()
.and_then(Path::parent)
.and_then(Path::parent)
.map(|p| p.join("usr/bin/bash.exe"))
.filter(|p| p.exists())
.unwrap_or_else(|| PathBuf::from("bash"))
} else {
PathBuf::from("bash")
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 6480c01

Please sign in to comment.