Visual studio 不能 运行 pre/post 提交挂钩:/usr/bin/env 'bash': 没有那个文件或目录

Visual studio cannot run pre/post commit hooks: /usr/bin/env 'bash': No such file or directory

我们有一个包含 .Net 解决方案的现有 git 存储库。我们正在添加一个 Web 应用程序。 Web 应用程序(angular) 位于特定的子文件夹中。

我们确实安装了一些预 post 提交挂钩,以确保文件被正确检查。使用 VS 代码或源代码树提交时一切正常。但是当我尝试直接从 Visual Studio 提交某些内容时,我收到此错误:

/usr/bin/env: 'bash': No such file or directory

有没有办法让它工作?

作为参考,这是我的钩子:

post-结帐

#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-checkout'.\n"; exit 2; }
git lfs post-checkout "$@"

post-提交

#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-commit'.\n"; exit 2; }
git lfs post-commit "$@"

post-合并

#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-merge'.\n"; exit 2; }
git lfs post-merge "$@"

cd ./Src/Frontend
npx git-pull-run --pattern "package-lock.json" --command "npm install"

预提交

#!/bin/sh
. "$(dirname "[=19=]")/_/husky.sh"

cd ./Src/Frontend
npm run lint

预推

#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/pre-push'.\n"; exit 2; }
git lfs pre-push "$@"

必须有一种方法可以使用 pre/post 提交挂钩,同时仍然能够在 VS Code 和 VS 中提交,对吧?我该怎么办?

首先检查您的 %PATH%,其中应包括 C:\Program Files\Git\bin,其中 bash.exe 所在。

或者为了测试修改 shebang directive 为:

#!C:/Program\ Files/Git/git-bash.exe