Merge pull request #9002 from nextcloud/git-hooks

Add QOL git hooks and gradle task to install them
This commit is contained in:
Andy Scherzinger 2021-09-25 17:31:15 +02:00 committed by GitHub
commit 611a3a221b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 0 deletions

View File

@ -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.

View File

@ -440,6 +440,14 @@ task ktlintFormat(type: JavaExec, group: "formatting") {
args "-F", "src/**/*.kt"
}
task installGitHooks(type: Copy, group: "development") {
description = "Install git hooks"
from("${project.rootDir}/scripts/hooks") {
include '*'
}
into '.git/hooks'
}
detekt {
reports {
xml {

6
scripts/hooks/pre-commit Executable file
View 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
View 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