lefthook
lefthook copied to clipboard
Lefthook with Git GUI
I'm currently using Husky and lint-staged with Tower, hooks with this setup work
I want to try Lefthook, but having problems
Tower https://www.git-tower.com/mac
set hooks with this command
[~/kit]$ yarn lefthook install -a
yarn run v1.21.1
$ /node_modules/.bin/lefthook install -a
SYNCING lefthook.yml
SERVED HOOKS: pre-commit, prepare-commit-msg
✨ Done in 0.45s.
[~/kit/.git/hooks]$ ls -la
total 16
drwxr-xr-x 4 pavel staff 128 Dec 24 17:01 .
drwxr-xr-x 17 pavel staff 544 Dec 24 17:01 ..
-rwxr-xr-x 1 pavel staff 370 Dec 24 17:01 pre-commit
-rwxr-xr-x 1 pavel staff 618 Dec 24 17:01 prepare-commit-msg
made one commit via Tower, linters have worked, but after this hooks have been deleted
[~/kit/.git/hooks]$ ls -la
total 0
drwxr-xr-x 2 pavel staff 64 Dec 24 17:03 .
drwxr-xr-x 17 pavel staff 544 Dec 24 17:03 ..
unfortunately could not find a way which git commands uses Tower when committing
Source tree https://www.sourcetreeapp.com/
Husky and lint-staged
git --no-optional-locks -c color.branch=false -c color.diff=false -c color.status=false -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree commit -q -F /var/folders/kj/w787fzx160130jtykf3kj1440000gn/T/SourceTreeTemp.Io8AzJ -a
Info: can't find node in PATH, trying to find a node binary on your system
husky > pre-commit (node v13.5.0)
Stashing changes... [started]
Stashing changes... [skipped]
→ No partially staged files found...
Running tasks... [started]
Running tasks for src/**/*.{js,jsx} [started]
Running tasks for src/**/.{scss,css} [started]
Running tasks for src/**/.{scss,css} [skipped]
→ No staged files match src/**/.{scss,css}
prettier --write [started]
prettier --write [completed]
eslint --fix [started]
eslint --fix [completed]
git add [started]
git add [completed]
Running tasks for src/**/*.{js,jsx} [completed]
Running tasks... [completed]
Lefthook hooks did not work when committing
git --no-optional-locks -c color.branch=false -c color.diff=false -c color.status=false -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree commit -q -F /var/folders/kj/w787fzx160130jtykf3kj1440000gn/T/SourceTreeTemp.fvWmZQ -a
Can't find lefthook in PATH
Can't find lefthook in PATH
Completed successfully
System info
macOS 10.15.2
git 2.24.1
lefthook 0.7.0
Do you know why hooks can disappear after a commit?
I don't know what happens when Tower execute scripts. For example VS Code
have debug console for that purpose: https://gyazo.com/a8b2ad0456d85e0495324eb7ce09e35f
Maybe Tower have something similar.
Obviosly the hooks script try to execute lefthook but it not accesable in PATH.
Can't find lefthook in PATH
You can try to debug .git/hooks/pre-commit
script directly.
Other variants:
- Install it globally and watch what will happen.
- Install 0.6.x version, maybe fresh one contain bugs.
Install it globally and watch what will happen.
same behavior with yarn global add @arkweid/lefthook
Install 0.6.x version, maybe fresh one contain bugs.
same behavior
after commit via Tower, linters have worked and after this hooks have been deleted
:man_shrugging: Is it works as expected from console?
yarn lefthook run pre-commit
yes
[~/kit]$ yarn lefthook run pre-commit
yarn run v1.21.1
$ /Users/pavel/kit/node_modules/.bin/lefthook run pre-commit
Lefthook v0.7.0
RUNNING HOOKS GROUP: pre-commit
prettier-style (SKIP. NO FILES FOR INSPECTING)
EXECUTE > eslint-js
$ /Users/pavel/kit/node_modules/.bin/prettier --write src/components/Badges/Badge/index.js
src/components/Badges/Badge/index.js 128ms
$ /Users/pavel/kit/node_modules/.bin/eslint --fix src/components/Badges/Badge/index.js
SUMMARY: (done in 2.61 seconds)
✔️ eslint-js
✨ Done in 2.84s.
also if I do commit from the console then everything works:
[~/kit]$ git commit -m "."
Lefthook v0.7.0
RUNNING HOOKS GROUP: pre-commit
prettier-style (SKIP. NO FILES FOR INSPECTING)
EXECUTE > eslint-js
yarn run v1.21.1
$ /Users/pavel/kit/node_modules/.bin/prettier --write src/components/Badges/Badge/index.js
src/components/Badges/Badge/index.js 110ms
✨ Done in 0.41s.
yarn run v1.21.1
$ /Users/pavel/kit/node_modules/.bin/eslint --fix src/components/Badges/Badge/index.js
✨ Done in 0.84s.
SUMMARY: (done in 1.62 seconds)
✔️ eslint-js
I'm having the same problem so I've sent a support request to Tower, I'll update this issue if I get a response.
I'm having this problem too.
I raised a bug report with Tower, stating how my pre-commit hooks would run successfully and then get deleted when committing through Tower, and how this was not the behaviour when committing via the command line. This was their response:
We have carefully reviewed our code here and we do not delete anything. All that Tower does is running the commit command. In this case, it appears that the hook scripts are not correctly executed, maybe starting in the wrong working directory. We did have similar issues in the past from users where the hook scripts were not executed in the root level of the Git folder.
Is is also possible that the hook scripts do remove files as part of some clean up phase and it's not safely scripted.
As far as we understand the combination of the two above factors can lead to the issues you've reported.
if you are on mac, the solution here is helping me on macOS Catalina,
https://community.atlassian.com/t5/Bitbucket-questions/SourceTree-Hook-failing-because-paths-don-t-seem-to-be-set/qaq-p/274792
especially sudo launchctl config user path `echo $PATH`
Facing the same issue when using SourceTree.
@SAGARSURI
Workaround:
sudo launchctl config user path "/usr/local/bin:$PATH"
Restart computer afterward Might not work for applications that are reopened at login (that were open when shutting down)
References:
- https://jira.atlassian.com/browse/SRCTREE-7184?focusedCommentId=2687804&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-2687804
- https://apple.stackexchange.com/a/198282/434751
Hey! Now you can provide your envs in an rc
file, you just need to specify one in the config. PATH tweaks can be done just there.
@mrexox do you have a "recipe" on how to use the "rc" file option? I am using Windows and the Windows Subsystem for Linux. So my Git environment is inside the WSL. My Git GUI (SmartGit) runs on Windows and reports "Can't find lefthook in PATH". Now I am trying to find a solution on how to solve it:
Hey @bennycode! How did you install lefthook?
You need to get the absolute path to lefthook executable and add it to your lefthook.rc
file
# lefthook.rc
PATH=$PATH:/path/to/a/folder/with/lefthook/executable
Then add rc
option to your lefthook.yml or lefthook-local.yml
# lefthook.yml
rc: /home/me/lefthook.rc # should be an absolute path
...