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
Show file tree
Hide file tree
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
updates after running black
  • Loading branch information
emanspeaks committed Jan 9, 2024
commit 50c74f45a0e8c3704930e5785b53af1095d36b72
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ Contributors are:
-Santos Gallegos <stsewd _at_ proton.me>
-Wenhan Zhu <wzhu.cosmos _at_ gmail.com>
-Eliah Kagan <eliah.kagan _at_ gmail.com>
-Randy Eckman <emanspeaks _at_ gmail.com>

Portions derived from other open source works and are clearly marked.
20 changes: 8 additions & 12 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,15 @@ def _get_default_bash_path(cls):
# with Git LFS, where Git LFS may be installed in Windows but not
# in WSL.
if not is_win:
return 'bash'
return "bash"
try:
wheregit = run(['where', Git.GIT_PYTHON_GIT_EXECUTABLE],
check=True, stdout=PIPE).stdout
wheregit = run(["where", Git.GIT_PYTHON_GIT_EXECUTABLE], check=True, stdout=PIPE).stdout
except CalledProcessError:
return 'bash.exe'
return "bash.exe"
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'
gitbash = gitroot / "bin" / "bash.exe"
return str(gitbash) if gitbash.exists() else "bash.exe"

@classmethod
def refresh_bash(cls, path: Union[None, PathLike] = None) -> bool:
Expand All @@ -370,24 +369,21 @@ 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'],
check=True, stdout=PIPE)
run([cls.GIT_PYTHON_BASH_EXECUTABLE, "--version"], check=True, stdout=PIPE)
has_bash = True
except CalledProcessError:
pass

# Warn or raise exception if test failed.
if not has_bash:
err = (
dedent(
f"""\
err = dedent(
f"""\
Bad bash executable.
The bash executable must be specified in one of the following ways:
- be included in your $PATH
- be set via ${cls._bash_exec_env_var}
- explicitly set via git.refresh_bash()
"""
)
)

# Revert to whatever the old_bash was.
Expand Down