Skip to content

Commit 4cb9500

Browse files
yerkeextrawurst
authored andcommitted
Use default shell instead of bash on Unix-like OS
1 parent 63a91fd commit 4cb9500

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Breaking Changes
11+
12+
#### Shell
13+
* use default shell instead of bash on Unix-like OS [[@yerke](https://github.com/yerke)] ([#2343](https://github.com/extrawurst/gitui/pull/2343))
14+
1015
### Fixes
1116
* respect env vars like `GIT_CONFIG_GLOBAL` ([#2298](https://github.com/extrawurst/gitui/issues/2298))
1217

git2-hooks/src/hookspath.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use git2::Repository;
33
use crate::{error::Result, HookResult, HooksError};
44

55
use std::{
6-
path::Path, path::PathBuf, process::Command, str::FromStr,
6+
env, path::Path, path::PathBuf, process::Command, str::FromStr,
77
};
88

99
pub struct HookPaths {
@@ -113,9 +113,10 @@ impl HookPaths {
113113

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

116-
let git_bash = find_bash_executable()
117-
.unwrap_or_else(|| PathBuf::from("bash"));
118-
let output = Command::new(git_bash)
116+
let git_shell = find_bash_executable()
117+
.or_else(find_default_unix_shell)
118+
.unwrap_or_else(|| "bash".into());
119+
let output = Command::new(git_shell)
119120
.args(bash_args)
120121
.current_dir(&self.pwd)
121122
// This call forces Command to handle the Path environment correctly on windows,
@@ -191,3 +192,8 @@ fn find_bash_executable() -> Option<PathBuf> {
191192
None
192193
}
193194
}
195+
196+
// Find default shell on Unix-like OS.
197+
fn find_default_unix_shell() -> Option<PathBuf> {
198+
env::var_os("SHELL").map(PathBuf::from)
199+
}

0 commit comments

Comments
 (0)