Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-push hook not working due to git-lfs? #356

Closed
jclaessens97 opened this issue Nov 11, 2022 · 2 comments · Fixed by #373
Closed

pre-push hook not working due to git-lfs? #356

jclaessens97 opened this issue Nov 11, 2022 · 2 comments · Fixed by #373
Labels
bug Something isn't working

Comments

@jclaessens97
Copy link

Summary

When I try to configure pre-push hook, it complains about git-lfs, but my repo doesn't use git-lfs.
pre-commit hook works perfectly. When actually trying to push a commit with a staged file I know will fail, it just works and pushes anyway.

Steps to reproduce

  1. Setup following config:
pre-push:
  parallel: true
  commands:
    lint:
      glob: '*.{ts,vue}'
      run: pnpm eslint {staged_files}
  1. npx lefthook install
  2. npx lefthook run pre-push

Expected results

❯ npx lefthook run pre-push
Lefthook v1.2.0
RUNNING HOOK: pre-push
lint: (SKIP. NO FILES FOR INSPECTION)

SUMMARY: (SKIP EMPTY)
(base)

Actual results

Lefthook v1.2.0
RUNNING HOOK: pre-push
Executing LFS Hook: `git lfs pre-push
This should be run through Git's pre-push hook.  Run `git lfs update` to install it.
git-lfs command failed
lint: (SKIP. NO FILES FOR INSPECTION)

SUMMARY: (SKIP EMPTY)
(base)

Possible Solution

I already tried "uninstalling" git lfs using git lfs uninstall and then I get the following output:

✖ git lfs uninstall
warning: error running /opt/homebrew/Cellar/git/2.36.0/libexec/git-core/git 'config' '--includes' '--global' '--remove-section' 'filter.lfs': 'fatal: no such section: filter.lfs' 'exit status 128'
Hook already exists: pre-push

	#!/bin/sh

	if [ "$LEFTHOOK" = "0" ]; then
	exit 0
	fi

	call_lefthook()
	{
	dir="$(git rev-parse --show-toplevel)"
	osArch=$(echo "$(uname)" | tr '[:upper:]' '[:lower:]')
	cpuArch=$(echo "$(uname -m)" | sed 's/aarch64/arm64/')

	if lefthook -h >/dev/null 2>&1
	then
	eval lefthook $@
	elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook"
	then
	eval "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook $@"
	elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook"
	then
	eval "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook $@"
	elif test -f "$dir/node_modules/lefthook/bin/index.js"
	then
	eval "$dir/node_modules/lefthook/bin/index.js $@"
	elif bundle exec lefthook -h >/dev/null 2>&1
	then
	bundle exec lefthook $@
	elif yarn lefthook -h >/dev/null 2>&1
	then
	yarn lefthook $@
	elif npx @evilmartians/lefthook

Hooks for this repository have been removed.
Global Git LFS configuration has been removed.
(base)
@jclaessens97 jclaessens97 added the bug Something isn't working label Nov 11, 2022
@mrexox
Copy link
Member

mrexox commented Nov 14, 2022

@jclaessens97 thank you for the issue! I see the two problems in your issue:

  1. git-lfs is trying to execute but it is not used in the project
  2. {staged_files} don't work for pre-push hook

Answers:

  1. I see that now lefthook only checks if there is a git-lfs executable in $PATH and runs it whenever you want it or not. However lefthook currently doesn't check the return value, it only prints all STDOUT and STDERR of git-lfs. I should consider checking whether git-lfs is configured in the repo or not and skip running LFS hooks based on that. I'll put it on my radar!
  2. For the pre-push hook if the files are already committed (you mentioned that you are pushing a commit with staged files, but it seems the files are already committed, so {staged_files} template doesn't reference them. I suggest using {push_files} to reference these files in your example. My bad - it is not referenced in documentation yet.

UPD: Added a {push_files} example in docs.

@jclaessens97
Copy link
Author

For point 2, I lowkey was expecting it to be something else, but I couldn't find anything about it, so great it's now added to the docs 👍🏻

For point 1, uninstalling git-lfs completely with homebrew seemed to fix it for now. That is until I have to use git-lfs again for another repo ofcourse 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants