Skip to content

Re-use commands and scripts between hooks #470

Closed Answered by technicalpickles
technicalpickles asked this question in Q&A
Discussion options

You must be logged in to vote

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

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@technicalpickles
Comment options

@mrexox
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by mrexox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants