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

Option for printing files changed by hook #1087

Closed
ArturGajowy opened this issue Jul 20, 2019 · 4 comments
Closed

Option for printing files changed by hook #1087

ArturGajowy opened this issue Jul 20, 2019 · 4 comments
Labels

Comments

@ArturGajowy
Copy link

Pre-commit detects changes made by hooks to the files in the repo. It'd be useful to have the option to print the changed files, as it's not always easy to make the tool we're running underneath do that for us.

My usage scenario would be having a scalafmt hook (a source formatter). Scalafmt doesn't output the files it modified, and has no option of requesting that.

I think though this is a generally useful feature, as many tools will be lacking in a similar way. Hence I propose print_changed_files: true to enable printing of the files changed by a hook.

@asottile
Copy link
Member

there's a duplicate for this somewhere in the tracker -- maybe #681, we don't actually know the changed filenames without a complicated and slow lookup (we're currently using "does the git diff bytes change between invocations)

you can run git diff afterwards to kind of find the changes?

@asottile
Copy link
Member

Or use --show-diff-on-failure in CI

@ArturGajowy
Copy link
Author

Yeah, I thought pre-commit actually knows which files changed - but you've explained it doesn't.

I think what I'm looking for with this and #1086 is better suited to be done in a post-commit hook (mostly). So I ended up running the formatter in a post-commit hook, and making a fixup! commit with its changes. This:

  • makes the change explicit
  • allows ignoring it (till rebase / at all)
  • doesn't require attempting the commit twice

@asottile
Copy link
Member

cheers! thanks for the issue :)

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

No branches or pull requests

2 participants