From 2fa45e3e7451b8c4d04c274254e42f1557ea0f58 Mon Sep 17 00:00:00 2001 From: "sas.fajri" Date: Mon, 27 Apr 2026 10:47:36 +0700 Subject: [PATCH] Sync on master push --- .githooks/post-commit | 6 +----- .githooks/pre-push | 35 +++++++++++++++++++++++++++++++++++ scripts/devcpone_sync.sh | 4 ++-- 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100755 .githooks/pre-push diff --git a/.githooks/post-commit b/.githooks/post-commit index b6ee897..4ce9978 100755 --- a/.githooks/post-commit +++ b/.githooks/post-commit @@ -1,8 +1,4 @@ #!/bin/sh set -eu -repo_root=$(git rev-parse --show-toplevel) - -if ! "$repo_root/scripts/devcpone_sync.sh"; then - printf '%s\n' "devcpone sync skipped/failed; commit kept intact" >&2 -fi +exit 0 diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 0000000..10a77a2 --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,35 @@ +#!/bin/sh +set -eu + +remote_name=$1 +remote_url=$2 + +case "$remote_url" in + *devcpone.aplikasi.web.id*|*10.9.10.205*) + ;; + *) + exit 0 + ;; +esac + +tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/devcpone-prepush.XXXXXX") +trap 'rm -rf "$tmpdir"' EXIT HUP INT TERM + +touch "$tmpdir/pushes" +cat > "$tmpdir/pushes" + +while read -r local_ref local_sha remote_ref remote_sha; do + case "$local_ref:$remote_ref" in + refs/heads/master:refs/heads/master) + branch=master + ;; + *) + continue + ;; + esac + + repo_root=$(git rev-parse --show-toplevel) + if ! "$repo_root/scripts/devcpone_sync.sh" "$branch"; then + printf '%s\n' "devcpone sync skipped/failed; push kept intact" >&2 + fi +done < "$tmpdir/pushes" diff --git a/scripts/devcpone_sync.sh b/scripts/devcpone_sync.sh index 92373c9..02f1b53 100755 --- a/scripts/devcpone_sync.sh +++ b/scripts/devcpone_sync.sh @@ -2,10 +2,10 @@ set -eu repo_root=$(git rev-parse --show-toplevel) -branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null || true) +branch=${1:-$(git symbolic-ref --quiet --short HEAD 2>/dev/null || true)} case "$branch" in - master|main) + master) ;; *) exit 0