question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migration mode does not work on Windows if legacy script starts with `#!/bin/sh`

See original GitHub issue

Repro steps:

  1. Create a git repo on windows, install git-lfs. It will add pre-push hook with this content:
#!/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 "$@"
  1. Install pre-commit and call pre-commit install -t pre-push It will rename pre-push to pre-push.legacy, command output:
pre-commit installed at .git\hooks\pre-commit
Running in migration mode with existing hooks at .git\hooks\pre-push.legacy
Use -f to use only pre-commit.
pre-commit installed at .git\hooks\pre-push
  1. Try pushing with git push It will fail with:
An unexpected error has occurred: ExecutableNotFoundError: Executable `/bin/sh` not found
Check the log at C:\Users\<username>\.cache\pre-commit\pre-commit.log
error: failed to push some refs to <repo url>

Expected: git push will work and will successfully call legacy git-lfs hook

Actual: git push fails


Log file content:

version information

pre-commit version: 2.7.1
sys.version:
    3.7.7 (default, May  6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)]
sys.executable: d:\envs\polymer\python.exe
os.name: nt
sys.platform: win32

error information

An unexpected error has occurred: ExecutableNotFoundError: Executable `/bin/sh` not found
Traceback (most recent call last):
  File "d:\envs\polymer\lib\site-packages\pre_commit\error_handler.py", line 63, in error_handler
    yield
  File "d:\envs\polymer\lib\site-packages\pre_commit\main.py", line 369, in main
    args=args.rest[1:],
  File "d:\envs\polymer\lib\site-packages\pre_commit\commands\hook_impl.py", line 211, in hook_impl
    retv, stdin = _run_legacy(hook_type, hook_dir, args)
  File "d:\envs\polymer\lib\site-packages\pre_commit\commands\hook_impl.py", line 42, in _run_legacy
    cmd = normalize_cmd((legacy_hook, *args))
  File "d:\envs\polymer\lib\site-packages\pre_commit\parse_shebang.py", line 82, in normalize_cmd
    exe = normexe(cmd[0])
  File "d:\envs\polymer\lib\site-packages\pre_commit\parse_shebang.py", line 61, in normexe
    _error('not found')
  File "d:\envs\polymer\lib\site-packages\pre_commit\parse_shebang.py", line 51, in _error
    raise ExecutableNotFoundError(f'Executable `{orig}` {msg}')
pre_commit.parse_shebang.ExecutableNotFoundError: Executable `/bin/sh` not found

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
asottilecommented, Sep 5, 2020

use /usr/bin/env sh

/bin/sh is not portable

0reactions
kmgamboa-mdsolcommented, Oct 12, 2022

Never mind, the folder was hidden … all good … thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

running pre-commit python package in Windows gives ...
I work in Windows where my teammates work on Macs. It looks like precommit is trying to reference the /bin/sh script which is...
Read more >
Troubleshooting Windows Subsystem for Linux | Microsoft Learn
Additionally, if you are using an ARM64 device and running this command from PowerShell, you will receive this error. Instead run wsl.exe from ......
Read more >
Move Legacy Content - Behind the Blackboard!
Execute movecontent script from migration archive to do the actual move. This will run in the background on Linux, and foreground on Windows...
Read more >
Cluster node initialization scripts | Databricks on AWS
Legacy global: run on every cluster. They are less secure than the new global init script framework, silently ignore failures, and cannot ......
Read more >
Candy: Legacy boot does not work - Freezes with CTRL-L
In both of these cases, keyboard input does not work anymore and I have to power ... merge the two: dd if=seabios.cbfs of=bios.bin...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found