Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ sonarqube {

// Install git hooks
tasks.register('installLocalGitHook', Copy) {
from new File(rootProject.rootDir, 'scripts/pre-commit')
from(new File(rootProject.rootDir, 'scripts')) {
include 'pre-commit', 'pre-push'
}
into new File(rootProject.rootDir, '.git/hooks')
filePermissions {
unix("rwxrwxr-x")
Expand Down
32 changes: 32 additions & 0 deletions scripts/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh
# pre-push hook (step 1: skeleton). Classifies pushes, never blocks.

ZERO_OID="0000000000000000000000000000000000000000"

log() {
printf '[pre-push] %s\n' "$*" >&2
}

classify() {
local_oid=$1
remote_ref=$2
remote_oid=$3

case "$remote_ref" in refs/heads/*) ;; *) echo "skip (not a branch)"; return ;; esac

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test

[ "$local_oid" = "$ZERO_OID" ] && { echo "skip (deletion)"; return; }
[ "$remote_oid" = "$ZERO_OID" ] && { echo "skip (new branch)"; return; }
if git merge-base --is-ancestor "$remote_oid" "$local_oid" 2>/dev/null; then
echo "fast-forward"
else
echo "NON-FAST-FORWARD (would need review check)"
fi
}

log "Starting history-rewrite check..."
while read -r _local_ref local_oid remote_ref remote_oid; do
log "${remote_ref#refs/heads/}: $(classify "$local_oid" "$remote_ref" "$remote_oid")"
done
log "Check finished: push allowed."
exit 0

# test
Loading