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

Only test the prospective commit: ignore unstaged changes. #1

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions pre-commit-8-4
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ if ! command_exists composer ; then
exit 1
fi

# Only test the prospective commit: ignore unstaged changes by stashing them.
OLD_STASH_SHA=$(git rev-parse -q --verify refs/stash)
git stash push -q --keep-index
NEW_STASH_SHA=$(git rev-parse -q --verify refs/stash)
if [ "$OLD_STASH_SHA" = "$NEW_STASH_SHA" ]; then
STASHED=false
else
STASHED=true
fi

FILES=$(git diff --cached --name-only $AGAINST);
TOP_LEVEL=$(git rev-parse --show-toplevel);

Expand Down Expand Up @@ -167,4 +177,8 @@ for FILE in $FILES; do

done

if $STASHED; then
git stash pop -q;
fi

exit $STATUS