houseabsolute / precious

One code quality tool to rule them all
Apache License 2.0
81 stars 4 forks source link

precious tidy --staged fails if post-checkout hook emits messages on STDOUT #23

Closed oalders closed 2 years ago

oalders commented 2 years ago

If you like, I can happily look into fixing this, but I wanted to check with you first.

Given the following post-checkout script:

cat .git/hooks/post-checkout
#!/bin/bash

echo "foo"

If I have a staged file, then git stash --keep-index is run by precious. This stash appears to trigger the post-checkout hook.

precious tidy --staged
💍 Tidying files staged for a git commit
[precious::precious][ERROR] Failed to run precious: Got unexpected stderr output from `git stash --keep-index`:
foo

I think the checkout might be happening here, but it's mostly a guess: https://github.com/git/git/blob/master/builtin/stash.c#L1621-L1622

As to why the hook output is sent to STDERR rather than STDOUT, I think this is likely the explanation: https://github.com/git/git/commit/e258eb4800e30da2adbdb2df8d8d8c19d9b443e4

If I have all of this correct, then maybe the logic which runs git stash --keep-index should be checking an exit code rather than STDERR?

autarch commented 2 years ago

I think this is as simple as changing a false to a true at src/basepaths.rs#133. It would also be nice to have a test for this too.

oalders commented 2 years ago

Great! I will add look at this tomorrow.

autarch commented 2 years ago

Fixed in v0.1.4.

oalders commented 2 years ago

Thanks!!!