Add simple git hooks and gradle task to install them
- Pre-commit hook checks ktlint and detekt - Pre-push hook checks signoff Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
27dd912bff
commit
556982ad8b
@ -119,6 +119,14 @@ There are three build variants
|
||||
* gplay: with Google Stuff (Push notification), used for Google Play Store
|
||||
* versionDev: based on master and library master, available as direct download and FDroid
|
||||
|
||||
### Git hooks
|
||||
We provide git hooks to make development process easier for both the developer and the reviewers.
|
||||
To install them, just run:
|
||||
|
||||
```bash
|
||||
./gradlew installGitHooks
|
||||
```
|
||||
|
||||
## Contribution process
|
||||
* Contribute your code in the branch 'master'. It will give us a better chance to test your code before merging it with stable code.
|
||||
* For your first contribution start a pull request on master.
|
||||
|
@ -440,6 +440,13 @@ task ktlintFormat(type: JavaExec, group: "formatting") {
|
||||
args "-F", "src/**/*.kt"
|
||||
}
|
||||
|
||||
task installGitHooks(type: Copy) {
|
||||
from('scripts/hooks') {
|
||||
include '*'
|
||||
}
|
||||
into '.git/hooks'
|
||||
}
|
||||
|
||||
detekt {
|
||||
reports {
|
||||
xml {
|
||||
|
6
scripts/hooks/pre-commit
Executable file
6
scripts/hooks/pre-commit
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
# Pre-commit hook: don't allow commits if detekt or ktlint fail. Skip with "git commit --no-verify".
|
||||
set -euo pipefail
|
||||
|
||||
./gradlew --daemon --quiet detekt
|
||||
./gradlew --daemon --quiet ktlint
|
31
scripts/hooks/pre-push
Executable file
31
scripts/hooks/pre-push
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
# Pre-push: Don't allow commits without Signed-off-by. Skip with "git push --no-verify".
|
||||
set -euo pipefail
|
||||
|
||||
z40=0000000000000000000000000000000000000000 # magic deleted ref
|
||||
|
||||
while read local_ref local_sha remote_ref remote_sha
|
||||
do
|
||||
if [ "$local_sha" != $z40 ]
|
||||
then
|
||||
if [ "$remote_sha" = $z40 ]
|
||||
then
|
||||
# New branch, examine all commits
|
||||
range="$(git merge-base master $local_sha)..$local_sha"
|
||||
else
|
||||
# Update to existing branch, examine new commits
|
||||
range="$remote_sha..$local_sha"
|
||||
fi
|
||||
|
||||
# Check for WIP commit
|
||||
commit=$(git rev-list --grep 'Signed-off-by' --invert-grep "$range")
|
||||
if [ -n "$commit" ]
|
||||
then
|
||||
echo >&2 "Found commits without signoff in $local_ref. Aborting push. Offending commits:"
|
||||
echo >&2 "$commit"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
Loading…
x
Reference in New Issue
Block a user