diff --git a/build.gradle b/build.gradle index 175f552f52..104784a105 100644 --- a/build.gradle +++ b/build.gradle @@ -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") diff --git a/scripts/pre-push b/scripts/pre-push new file mode 100644 index 0000000000..a63a299952 --- /dev/null +++ b/scripts/pre-push @@ -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 + [ "$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 \ No newline at end of file