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

Accessing git hook arguments from files command #315

Closed
BasixKOR opened this issue Aug 10, 2022 · 4 comments
Closed

Accessing git hook arguments from files command #315

BasixKOR opened this issue Aug 10, 2022 · 4 comments

Comments

@BasixKOR
Copy link

I've tried to use post-checkout hook and I tried to diff the changed files using git diff --name-only {1} {0} but I noticed this doesn't work and {files} just printed files.

@BasixKOR
Copy link
Author

Closing as it is likely a duplicate of #269.

@mrexox
Copy link
Member

mrexox commented Aug 10, 2022

Hey, @BasixKOR ! Could you provide your lefthook.yml content? #314 fixes the quoting issue on Windows, but does nothing with git arguments like {1} and {0}.

Also {0}, {1}, and other git hook args substitutions don't happen on files parameter, but if you provide a usecase I can add this feature!

@mrexox
Copy link
Member

mrexox commented Aug 10, 2022

Also when you use {0} - it prints all git arguments for the hook. Use {1} for first argument and {2} for the second. See https://github.com/evilmartians/lefthook/blob/master/docs/full_guide.md#git-hook-argument-shorthands-in-commands

@fabn
Copy link
Contributor

fabn commented Mar 31, 2023

Also {0}, {1}, and other git hook args substitutions don't happen on files parameter, but if you provide a usecase I can add this feature!

Hi @mrexox I was looking for the same thing, I want to perform bundle install in a ruby project whenever a Gemfile is changed. So my idea was something about

post-checkout:
  commands:
    01-bundle-install:
      files: git diff --name-only {1} {2} | grep -i Gemfile
      run: bundle install

But is not working because {1} and {2} are not forwarded to files. Is there any workaround apart from writing a custom script in run that do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants