Add devcpone sync hook
This commit is contained in:
5
.githooks/post-commit
Executable file
5
.githooks/post-commit
Executable 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
58
scripts/devcpone_sync.sh
Executable 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"
|
||||||
Reference in New Issue
Block a user