Add devcpone sync hook

This commit is contained in:
sas.fajri
2026-04-27 10:31:37 +07:00
parent 8347aef8f4
commit 742052aa42
2 changed files with 63 additions and 0 deletions

5
.githooks/post-commit Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
set -eu
repo_root=$(git rev-parse --show-toplevel)
"$repo_root/scripts/devcpone_sync.sh"

58
scripts/devcpone_sync.sh Executable file
View File

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