Commit 362ece96 authored by Tomáš Hübelbauer's avatar Tomáš Hübelbauer

Update doc with latest findings

parent cda180d9
......@@ -16,11 +16,9 @@ Since the pre-commit hook will run as a Bash script through MinGW, but we can't
On Windows 10, we can invoke `bash` which will pick up the default WSL distro (learn about managing distros using [`wslconfig`](https://docs.microsoft.com/en-us/windows/wsl/wsl-config) to see how to change the default) and we can have that execute our commands. So we can write a Unix script and use that on both Windows and Unix. Problem is, `bash` in MinGW will map to MinGW Bash. `bash.exe` to MinGW Bash, too. I have not had success invoking `bash.exe` so that it actually runs WSL and not MinGW Bash. I managed to somehow not make it work even with full `bash.exe` path (trouble passing script there). One could try and invoke a specific distro directly (`ubuntu` or `opensuse-42`), but that gives a *Permission denied* error as of now because the distro paths go to system & hidden perm'd folder in Windows.
One last alias for `bash.exe` we could use is `wsl`, but while that works fine in Batch and PowerShell, MinGW doesn't run it.
One last alias for `bash.exe` we could use is `wsl`, but while that works fine in Batch and PowerShell, MinGW invoked manually runs it, but MinGW through Git won't. Same problem as with `bash.exe` but without the overriding issue. Can't invoke this for shit.
So yeah, we need to settle for PowerShell.
We're using the [bash shebang](https://stackoverflow.com/a/10383546/2715716) because we rely on `bash` anyway so `sh` won't cut it.
So yeah, I need to settle for PowerShell.
```sh
cd .git/hooks
......@@ -28,18 +26,16 @@ cp pre-commit.sample pre-commit
code pre-commit
```
`.git/hooks/pre-commit.sh`
`.git/hooks/pre-commit`
```sh
#!/usr/bin/env bash
# Run `bash` on Unix, WSL on Windows
bash cmd/pre-commit.sh
# Use PowerShell on Windows, Bash on Unix
powershell cmd/pre-commit.ps1 || bash cmd/pre-commit.sh
```
`cmd/pre-commit.sh`
`cmd/pre-commit.ps1`
```sh
#!/usr/bin/env bash
# Rely on host system having the `7z` prerequisite
echo "Hello from WSL!"
```powershell
Write-Output "Hello from PowerShell"
```
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment