Re-use commands and scripts between hooks #470
-
Is there a way to share commands between the different hooks? I'm trying to support pre-commit while also evaluating moving most of those to pre-push, and ended using YAML anchors and references initially, ie: # lefthook.yml
pre-commit:
commands:
rubocop: &rubocop
tags: backend style
glob: "{Rakefile,Brewfile,Gemfile,*.{rb,rake,rabl,arb}}"
run: bin/rubocop --color --force-exclusion --format simple --autocorrect {staged_files}
auto_stage: true
pre-push:
skip: true
commands:
rubocop:
<<: *rubocop I use pre-commit:
skip: true
pre-push:
skip: false This works for pre-commit, I just got a report from someone testing it that the push didn't actually match anything. It turns out there is a difference between Some initial ideas I am considering:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey! If I correctly understood your question, you want to have similar commands for both # lefthook.yml
pre-commit:
files: git diff --name-only --cached --diff-filter=ACMR
commands:
rubocop: &rubocop
tags: backend style
glob: "{Rakefile,Brewfile,Gemfile,*.{rb,rake,rabl,arb}}"
run: bin/rubocop --color --force-exclusion --format simple --autocorrect {files}
auto_stage: true
pre-push:
files: git diff --name-only HEAD @{push}
commands:
rubocop:
<<: *rubocop |
Beta Was this translation helpful? Give feedback.
-
Final answer, based on @mrexox's initial message and followup: # lefthook.yml
pre-commit:
files: git diff --name-only --cached --diff-filter=ACMR
commands:
rubocop: &rubocop
tags: backend style
glob: "{Rakefile,Brewfile,Gemfile,*.{rb,rake,rabl,arb}}"
run: bin/rubocop --color --force-exclusion --format simple --autocorrect {files}
auto_stage: true
pre-push:
files: git diff --name-only HEAD @{push} || git diff --name-only HEAD main # or 'master', depends on the primary branch name you have
commands:
rubocop:
<<: *rubocop |
Beta Was this translation helpful? Give feedback.
Final answer, based on @mrexox's initial message and followup: