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

Problem with running pronto in a pre-commit hook #263

Closed
grodowski opened this issue Sep 14, 2017 · 3 comments
Closed

Problem with running pronto in a pre-commit hook #263

grodowski opened this issue Sep 14, 2017 · 3 comments
Labels

Comments

@grodowski
Copy link
Contributor

grodowski commented Sep 14, 2017

Hey!

I have run into a problem with setting up pronto as a pre-commit git hook.

Given there are new rubocop warnings and I have the below script in .git/hooks/pre-commit...

#!/bin/bash
bundle exec pronto run --staged --runner rubocop --exit-code

Pronto does what is expected and shows the rubocop warnings when I run:

git add .
git commit -m "test"

But unfortunately I get no rubocop output and a false-positive exit status 0 on

git commit -am "test"

This is strange and I've been trying to understand the reason. Traced it back to the below line, where rugged returns an empty diff for the staged option (just in the second use case).

[head_commit_sha, head.diff(@repo.index, options)]

Any help would be welcome!

Edit: I am using pronto 0.9.5

@mmozuras mmozuras added the bug label Oct 15, 2017
@mmozuras
Copy link
Member

@grodowski thanks for reporting the issue! 🙇

Managed to reproduce it by following the steps you've outlined. Tried a couple of other cases and it shows warnings when using --staged with:

git add .
git commit -am "test"

It also shows error when using --unstaged flag with:

git commit -am "test"

That was an AHA moment for me. One workaround that works: having two pre-commit scripts. One for --unstaged flag, the other one for --staged.

@prontolabs/core I also wonder if we should support an option that covers both --unstaged and --staged with a single flag? Or support combining multiple flags? Thoughts?

@printercu
Copy link

printercu commented Dec 26, 2018

Just faced this issue. Using master to resolve Rugged::TreeError.
@mmozuras do you have any updates on how to make it work with both --staged --index given?

As a workaround I run pronto second time for new files:

bundle exec pronto run --index --exit-code

new_files=`git diff --cached --name-status | (grep -E "^[A]" || true) | cut -f2-`
[ -n "$new_files" ] && bundle exec pronto run --staged --exit-code

However 1st call checks not staged files too.

@grodowski
Copy link
Contributor Author

@mmozuras I've been working on a coverage tool that integrates with git (and Pronto), which combines staged + unstaged by default, like this. I might be able to port this to pronto as a new flag or a combination of the two.

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

No branches or pull requests

3 participants