59 lines
1.3 KiB
Bash
Executable File
59 lines
1.3 KiB
Bash
Executable File
#!/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"
|