Skip to content

Override bash executable, defaulting to Git for Windows git bash over WSL bash #1791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix typos preventing import
  • Loading branch information
emanspeaks committed Jan 9, 2024
commit 4bde10debd95e59ad8702be515ae4bbc9fe0a8ee
12 changes: 7 additions & 5 deletions git/cmd.py
Original file line number Diff line number Diff line change
@@ -334,8 +334,9 @@ def _get_default_bash_path(cls):
# This addresses issues where git hooks are intended to run assuming
# the "native" Windows environment as seen by git.exe rather than
# inside the git sandbox of WSL, which is likely configured
# independetly of the Windows Git. A noteworthy example are repos with
# Git LFS, where Git LFS may be installed in Windows but not in WSL.
# independently of the Windows Git. A noteworthy example are repos
# with Git LFS, where Git LFS may be installed in Windows but not
# in WSL.
if not is_win:
return 'bash'
try:
@@ -346,7 +347,7 @@ def _get_default_bash_path(cls):
gitpath = Path(wheregit.decode(defenc).splitlines()[0])
gitroot = gitpath.parent.parent
gitbash = gitroot / 'bin' / 'bash.exe'
return str(gitbash) if gitbash.exists else 'bash.exe'
return str(gitbash) if gitbash.exists() else 'bash.exe'

@classmethod
def refresh_bash(cls, path: Union[None, PathLike] = None) -> bool:
@@ -357,7 +358,7 @@ def refresh_bash(cls, path: Union[None, PathLike] = None) -> bool:
new_bash = os.path.abspath(new_bash)
else:
new_bash = os.environ.get(cls._bash_exec_env_var)
if new_bash is None:
if not new_bash:
new_bash = cls._get_default_bash_path()

# Keep track of the old and new bash executable path.
@@ -369,7 +370,8 @@ def refresh_bash(cls, path: Union[None, PathLike] = None) -> bool:
# executed for whatever reason.
has_bash = False
try:
run([cls.GIT_PYTHON_BASH_EXECUTABLE, '--version'])
run([cls.GIT_PYTHON_BASH_EXECUTABLE, '--version'],
check=True, stdout=PIPE)
has_bash = True
except CalledProcessError:
pass
1 change: 1 addition & 0 deletions randytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import git