Use default shell instead of bash on Unix-like OS

This commit is contained in:
Yerke Tulibergenov 2024-08-22 19:37:46 -07:00 committed by extrawurst
parent 63a91fd281
commit 4cb9500cd9
2 changed files with 15 additions and 4 deletions

View File

@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Breaking Changes
#### Shell
* use default shell instead of bash on Unix-like OS [[@yerke](https://github.com/yerke)] ([#2343](https://github.com/extrawurst/gitui/pull/2343))
### Fixes
* respect env vars like `GIT_CONFIG_GLOBAL` ([#2298](https://github.com/extrawurst/gitui/issues/2298))

View File

@ -3,7 +3,7 @@ use git2::Repository;
use crate::{error::Result, HookResult, HooksError};
use std::{
path::Path, path::PathBuf, process::Command, str::FromStr,
env, path::Path, path::PathBuf, process::Command, str::FromStr,
};
pub struct HookPaths {
@ -113,9 +113,10 @@ impl HookPaths {
log::trace!("run hook '{:?}' in '{:?}'", hook, self.pwd);
let git_bash = find_bash_executable()
.unwrap_or_else(|| PathBuf::from("bash"));
let output = Command::new(git_bash)
let git_shell = find_bash_executable()
.or_else(find_default_unix_shell)
.unwrap_or_else(|| "bash".into());
let output = Command::new(git_shell)
.args(bash_args)
.current_dir(&self.pwd)
// This call forces Command to handle the Path environment correctly on windows,
@ -191,3 +192,8 @@ fn find_bash_executable() -> Option<PathBuf> {
None
}
}
// Find default shell on Unix-like OS.
fn find_default_unix_shell() -> Option<PathBuf> {
env::var_os("SHELL").map(PathBuf::from)
}