Improvements to git hooks
- pre-commit: Suppress all output and show reduced results. This is more concise and avoids unreadable errors when committing from an IDE - pre-push: Format with shell formatter, fix typo Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
c5a06b7225
commit
a38edb92dd
@ -1,6 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Pre-commit hook: don't allow commits if detekt or ktlint fail. Skip with "git commit --no-verify".
|
# Pre-commit hook: don't allow commits if detekt or ktlint fail. Skip with "git commit --no-verify".
|
||||||
set -euo pipefail
|
echo "Running pre-commit checks."
|
||||||
|
|
||||||
./gradlew --daemon --quiet detekt
|
if ! ./gradlew --daemon ktlint &>/dev/null; then
|
||||||
./gradlew --daemon --quiet ktlint
|
echo >&2 "Lint failed! See report at file://$(pwd)/build/ktlint.txt"
|
||||||
|
echo >&2 "Hint: fix most lint errors with ./gradlew ktlintFormat"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! ./gradlew --daemon detekt &>/dev/null; then
|
||||||
|
echo >&2 "Detekt failed! See report at file://$(pwd)/build/reports/detekt/detekt.html"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
@ -4,12 +4,9 @@ set -euo pipefail
|
|||||||
|
|
||||||
z40=0000000000000000000000000000000000000000 # magic deleted ref
|
z40=0000000000000000000000000000000000000000 # magic deleted ref
|
||||||
|
|
||||||
while read local_ref local_sha remote_ref remote_sha
|
while read local_ref local_sha remote_ref remote_sha; do
|
||||||
do
|
if [ "$local_sha" != $z40 ]; then
|
||||||
if [ "$local_sha" != $z40 ]
|
if [ "$remote_sha" = $z40 ]; then
|
||||||
then
|
|
||||||
if [ "$remote_sha" = $z40 ]
|
|
||||||
then
|
|
||||||
# New branch, examine all commits
|
# New branch, examine all commits
|
||||||
range="$(git merge-base master $local_sha)..$local_sha"
|
range="$(git merge-base master $local_sha)..$local_sha"
|
||||||
else
|
else
|
||||||
@ -17,11 +14,10 @@ do
|
|||||||
range="$remote_sha..$local_sha"
|
range="$remote_sha..$local_sha"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for WIP commit
|
# Check for commits without sign-off
|
||||||
commit=$(git rev-list --grep 'Signed-off-by' --invert-grep "$range")
|
commit=$(git rev-list --grep 'Signed-off-by' --invert-grep "$range")
|
||||||
if [ -n "$commit" ]
|
if [ -n "$commit" ]; then
|
||||||
then
|
echo >&2 "Found commits without sign-off in $local_ref. Aborting push. Offending commits:"
|
||||||
echo >&2 "Found commits without signoff in $local_ref. Aborting push. Offending commits:"
|
|
||||||
echo >&2 "$commit"
|
echo >&2 "$commit"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user