From f644269282ad9a53c679984e6b670f84c7965935 Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Wed, 23 Oct 2024 10:36:05 +0300 Subject: [PATCH] fix: skip git-lfs on pre-push hook when calling manually --- internal/git/lfs.go | 19 +++++++------------ internal/lefthook/runner/runner.go | 5 +++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/git/lfs.go b/internal/git/lfs.go index 142e8bf8..ef9f1ef4 100644 --- a/internal/git/lfs.go +++ b/internal/git/lfs.go @@ -9,11 +9,11 @@ const ( LFSConfigFile = ".lfsconfig" ) -var lfsHooks = [...]string{ - "post-checkout", - "post-commit", - "post-merge", - "pre-push", +var lfsHooks = map[string]struct{}{ + "post-checkout": {}, + "post-commit": {}, + "post-merge": {}, + "pre-push": {}, } // IsLFSAvailable returns 'true' if git-lfs is installed. @@ -25,11 +25,6 @@ func IsLFSAvailable() bool { // IsLFSHook returns whether the hookName is supported by Git LFS. func IsLFSHook(hookName string) bool { - for _, lfsHookName := range lfsHooks { - if lfsHookName == hookName { - return true - } - } - - return false + _, ok := lfsHooks[hookName] + return ok } diff --git a/internal/lefthook/runner/runner.go b/internal/lefthook/runner/runner.go index 4aa2bba1..69c26753 100644 --- a/internal/lefthook/runner/runner.go +++ b/internal/lefthook/runner/runner.go @@ -129,6 +129,11 @@ func (r *Runner) runLFSHook(ctx context.Context) error { return nil } + // Skip triggering LFS for pre-push hook when triggered manually + if len(r.GitArgs) == 0 && r.HookName == "pre-push" { + return nil + } + lfsRequiredFile := filepath.Join(r.Repo.RootPath, git.LFSRequiredFile) lfsConfigFile := filepath.Join(r.Repo.RootPath, git.LFSConfigFile)