From 742052aa4239e08edbce89d5a90fa173486269f2 Mon Sep 17 00:00:00 2001 From: "sas.fajri" Date: Mon, 27 Apr 2026 10:31:37 +0700 Subject: [PATCH] Add devcpone sync hook --- .githooks/post-commit | 5 ++++ scripts/devcpone_sync.sh | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 .githooks/post-commit create mode 100755 scripts/devcpone_sync.sh diff --git a/.githooks/post-commit b/.githooks/post-commit new file mode 100755 index 0000000..dae88d8 --- /dev/null +++ b/.githooks/post-commit @@ -0,0 +1,5 @@ +#!/bin/sh +set -eu + +repo_root=$(git rev-parse --show-toplevel) +"$repo_root/scripts/devcpone_sync.sh" diff --git a/scripts/devcpone_sync.sh b/scripts/devcpone_sync.sh new file mode 100755 index 0000000..6f795a6 --- /dev/null +++ b/scripts/devcpone_sync.sh @@ -0,0 +1,58 @@ +#!/bin/sh +set -eu + +repo_root=$(git rev-parse --show-toplevel) +cd "$repo_root" + +branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null || true) +if [ "$branch" != "master" ]; then + exit 0 +fi + +remote_host=${DEVCPONE_SYNC_HOST:-one@devcpone.aplikasi.web.id} +remote_path=${DEVCPONE_SYNC_PATH:-/home/one/project/one/one-ui/} +ssh_key=${DEVCPONE_SYNC_KEY:-/Users/fajrihardhitamurti/id_rsa} +ssh_port=${DEVCPONE_SYNC_PORT:-22} + +tmpfile=$(mktemp) +trap 'rm -f "$tmpfile"' EXIT INT TERM HUP + +if git rev-parse --verify HEAD^ >/dev/null 2>&1; then + diff_range='HEAD^ HEAD' +else + diff_range='--root HEAD' +fi + +git diff-tree --no-commit-id --name-status -r $diff_range | while IFS="$(printf '\t')" read -r status path1 path2; do + case "$path1" in + .git/*|.githooks/*|scripts/*|.codex/*) + continue + ;; + esac + + case "$status" in + A|M|T|C) + printf '%s\n' "$path1" >> "$tmpfile" + ;; + R*) + case "$path2" in + .git/*|.githooks/*|scripts/*|.codex/*) + continue + ;; + esac + printf '%s\n' "$path2" >> "$tmpfile" + ;; + D) + : + ;; + esac +done + +if [ ! -s "$tmpfile" ]; then + exit 0 +fi + +sort -u "$tmpfile" -o "$tmpfile" + +ssh_cmd="ssh -i $ssh_key -p $ssh_port -o BatchMode=yes" +rsync -a --relative --files-from="$tmpfile" -e "$ssh_cmd" ./ "$remote_host:$remote_path"