lefthook
lefthook copied to clipboard
Lefthook on windows can run powershell/pwsh as a runner
:wrench: Summary
When attempting to run Lefthook on Windows, it doesn't seem to identify/see the config file.
Lefthook version
1.2.9 0e6aa810510174063b6040b07e3cbdd9c78fba45
Steps to reproduce
Install
- Download lefthook_1.2.9_Windows_x86_64.exe > C:\Lefthook
- Add to Path:
$Path = [Environment]::GetEnvironmentVariable("PATH", "User") + [IO.Path]::PathSeparator + "C:\Lefthook"
[Environment]::SetEnvironmentVariable( "Path", $Path, "User" )
Prepare Repo
push-location c:\repo
lefthook_1.2.9_Windows_x86_64.exe install
lefthook_1.2.9_Windows_x86_64.exe add commit-msg
tree
C:\REPO
├───.lefthook
│ └───commit-msg
└───.lefthook-local
└───commit-msg
Files
- repo\lefthook.yml
# 'pwsh.exe -NoProfile -ExecutionPolicy Bypass -File ".\convcoGitHook.ps1 -MessagePath '$1'"'
commit-msg:
conventional-commits-check:
scripts:
"convcoGitHook.ps1":
runner: pwsh.exe -NoProfile -ExecutionPolicy Bypass -File
- repo.lefthook\commit-msg\convcoGitHook.ps1
Write-Host "convcoGitHook.ps1 EXECUTED!!!!"
Expected results
> lefthook_1.2.9_Windows_x86_64.exe run commit-msg -v
Lefthook v1.2.9
SYNCING
SERVED HOOKS: commit-msg
RUNNING HOOK: commit-msg
convcoGitHook.ps1: (???Executing???)
convcoGitHook.ps1 EXECUTED!!!!
SUMMARY: (???NOT EMPTY???)
>
Actual results
> lefthook_1.2.9_Windows_x86_64.exe run commit-msg -v
Lefthook v1.2.9
SYNCING
SERVED HOOKS: commit-msg
RUNNING HOOK: commit-msg
convcoGitHook.ps1: (SKIP BY NOT EXIST IN CONFIG)
SUMMARY: (SKIP EMPTY)
>
Possible Solution
It is as if the config file isn't getting picked up/read/processed. The file lefthoook.yml
is located in the root of the repo c:\repo
which was the location it was created during install.
-v
argument doesn't seem to include any additional output,
Per usage and configuration, I haven't been able to validate all the configuration file names/locations it would check.
While I'm not a Go programmer, I'm happy to do the heavy lifting on any/all testing for Windows since I know it's not the main focus.
- at the end of the day, I'm trying to use pwsh.exe as a runner (possibly with some parameters)
- validate the correct configuration file location that is expected.
Screenshots (if appropriate)
Hey! Thank you for the issue. Could you show your lefthook.yml
config content, please?
Yeah, I included it above, repo\lefthook.yml
But here it is (in it's entirety;I did remove the default content)
# 'pwsh.exe -NoProfile -ExecutionPolicy Bypass -File ".\convcoGitHook.ps1 -MessagePath '$1'"'
commit-msg:
conventional-commits-check:
scripts:
"convcoGitHook.ps1":
runner: pwsh.exe -NoProfile -ExecutionPolicy Bypass -File
I get the same result if I use the above runner or one of the following:
runner: pwsh.exe
#OR
runner: pwsh
Hey! I guess you've misconfigured lefthook.yml
. Could you try this?
# 'pwsh.exe -NoProfile -ExecutionPolicy Bypass -File ".\convcoGitHook.ps1 -MessagePath '$1'"'
commit-msg:
scripts:
"convcoGitHook.ps1":
runner: pwsh.exe -NoProfile -ExecutionPolicy Bypass -File
There is conventional-commits-check:
key that breaks the config format (although no error is thrown :thinking:)
Ok, Made the change to lefthook.yml
# 'pwsh.exe -NoProfile -ExecutionPolicy Bypass -File ".\convcoGitHook.ps1 -MessagePath '$1'"'
commit-msg:
scripts:
"convcoGitHook.ps1":
runner: pwsh.exe -NoProfile -ExecutionPolicy Bypass -File
Results: No change
> lefthook_1.2.9_Windows_x86_64.exe run commit-msg -v
Lefthook v1.2.9
SYNCING
SERVED HOOKS: commit-msg
RUNNING HOOK: commit-msg
convcoGitHook.ps1: (SKIP BY NOT EXIST IN CONFIG)
SUMMARY: (SKIP EMPTY)
Sorry for the delay. Could you share a github repository with the example configuration? I mean lefthook.yml
, .lefthook/pre-commit/*
scripts and other files that are related to lefthook configuration. It would help to investigate the issue because it's hard for me to identify the problem :thinking:
Sorry for the delay. Could you share a github repository with the example configuration? I mean
lefthook.yml
,.lefthook/pre-commit/*
scripts and other files that are related to lefthook configuration. It would help to investigate the issue because it's hard for me to identify the problem 🤔
Hey @mrexox, I apologize for the delayed response as work got in the way of responding... I've created a test repo to do further testing as requested:
https://github.com/j-byrnes/testLefthook
Since I see you've had several releases since my original post, I wasn't sure if the procedure for working on Windows had been updated.
Please let me know what the next steps are for troubleshooting.
Hey @j-byrnes! Thank you for the test repo. I just noticed that the .lefthook/
contains the script testScript.ps1
. But the correct path for scripts is - .lefthook/<hook name>/<script name>
. See docs for details.
Could you please move the testScript.ps1
into .lefthook/commit-msg/
folder and check if it works?
Thanks for the catch, it looks a little better... now the output is the following
> lefthook run commit-msg
Lefthook v1.3.9
RUNNING HOOK: commit-msg
testScript.ps1: (skip) not specified in config file
SUMMARY: (SKIP EMPTY)
I've commited the changes to the repo... not sure what it is referring to that the file isn't specified in the config file.
Oh, I see. The problem is - script name is converted to the lowercase when YAML is parsed. That's the problem I guess :confused:
As a workaround I can suggest making script name in all lower case letters with -
or _
to separate words. I'll check if it is possible to save the original case when parsing.
That worked, I'm going to explore testing a little more, that may be it.
Also, one more question: Do you have any suggestions for the "rc" configuration, does it have to be shell and can it use relative path names?
The need is to leverage rc to set an environment variable to add lefthook path during execution.
You can specify this:
# lefthook.yml
rc: ./testrc.sh
# ...
But this is not tested enough, however it should work (note ./
is important, it doesn't work for me without it)