microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.05k stars 29.22k forks source link

`git-hook/pre-push: exec: python: not found` #193634

Open JordanLongstaff opened 1 year ago

JordanLongstaff commented 1 year ago

Does this issue occur when all extensions are disabled?: N/A

I have a pre-push hook that runs a Python program:

#!/usr/bin/env bash
# ... irrelevant comments ...
exec python -m server.devcheck pre-push

The Python executable definitely exists on my computer, yet this stops me from being able to push commits using VS Code. Output:

2023-09-20 19:23:47.810 [info] > git push -u origin branch-name-redacted [957ms]
2023-09-20 19:23:47.810 [info] git-hooks/pre-push: line 4: exec: python: not found
error: failed to push some refs to 'github.com:EncircleInc/encircle.git'

This has to be an issue with VS Code, because I can run the above git push -u ... command from the CLI and it works with no problems. Whatever environment VS Code runs git in, it's not one that recognizes the executables in my shell.

Either this is a bug, or I need to configure my settings somehow. If it's the latter, please offer whatever help you can.

Steps to Reproduce:

  1. Write any Python program you wish (it could be just a "Hello, world" program) and write a pre-push hook to run it like the above example.
  2. Make a branch and add a commit to it.
  3. Try publishing the branch through VS Code. The expectation is that it runs git push -u and successfully pushes the branch to the remote. The actual behaviour is that it fails to find Python.
lszomoru commented 1 year ago

@brettcannon, does this one ring a bell? Thanks!

brettcannon commented 1 year ago

Nope, this isn't a specific issue that I'm aware of if Python is globally installed and accessible on PATH (assuming that's how VS Code executes pre-commit hooks).

bahung1221 commented 10 months ago

Same issue when using git in vscode on macOS, it worked when using git in terminal but not in vscode. (It previously worked but the issue happened recently)

Screenshot 2023-12-15 at 09 47 04
Link512 commented 7 months ago

I'm currently experiencing the same(ish) issue with a golang repo. I have a pre-commit hook that runs a linter. If I do git commit from the terminal it works, however trying to commit from vscode gives me the following

> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file - -S
/home/<SNIP>/dotgit/hooks/pre-commit-format-lint:7: command not found: goimports
/home/<SNIP>/dotgit/hooks/pre-commit-format-lint:23: command not found: golangci-lint

Somehow, when doing a commit via vscode, my shell's PATH variable isn't read. I've had this issue in the past, but then got fixed when I updated vscode. Now it was reintroduced with the February 1.87 update.