Prevent devone delete sync
This commit is contained in:
@@ -4,3 +4,5 @@ Ini adalah BE untuk IBL
|
||||
|
||||
Jalankan `./scripts/install_devone_sync_hooks.sh` sekali untuk mengaktifkan hook Git lokal.
|
||||
Setelah itu, commit atau merge ke `main` akan otomatis sync file yang berubah ke `devone.aplikasi.web.id:/home/one/project/one/one-api-lab/` memakai `scripts/sync_devone_changed_files.sh`.
|
||||
Sync ini hanya mengirim file baru atau file yang berubah.
|
||||
Perubahan rename, move, atau delete sengaja di-skip supaya file dan folder di devone tidak ikut terhapus atau berpindah.
|
||||
|
||||
@@ -39,16 +39,20 @@ fi
|
||||
tmpdir="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmpdir"' EXIT
|
||||
changed_list="$tmpdir/changed-files.z"
|
||||
skipped_list="$tmpdir/skipped-files.txt"
|
||||
|
||||
case "$MODE" in
|
||||
commit)
|
||||
git -C "$ROOT_DIR" diff-tree --no-commit-id --root --diff-filter=ACMR --name-only -r -z HEAD > "$changed_list"
|
||||
git -C "$ROOT_DIR" diff-tree --no-commit-id --root --diff-filter=ACM --name-only -r -z HEAD > "$changed_list"
|
||||
git -C "$ROOT_DIR" diff-tree --no-commit-id --root --diff-filter=DR --summary -r HEAD > "$skipped_list" || true
|
||||
;;
|
||||
merge)
|
||||
if git -C "$ROOT_DIR" rev-parse -q --verify ORIG_HEAD >/dev/null 2>&1; then
|
||||
git -C "$ROOT_DIR" diff --diff-filter=ACMR -z --name-only ORIG_HEAD HEAD > "$changed_list"
|
||||
git -C "$ROOT_DIR" diff --diff-filter=ACM -z --name-only ORIG_HEAD HEAD > "$changed_list"
|
||||
git -C "$ROOT_DIR" diff --diff-filter=DR --summary ORIG_HEAD HEAD > "$skipped_list" || true
|
||||
else
|
||||
git -C "$ROOT_DIR" diff-tree --no-commit-id --root --diff-filter=ACMR -r -z HEAD > "$changed_list"
|
||||
git -C "$ROOT_DIR" diff-tree --no-commit-id --root --diff-filter=ACM -r -z HEAD > "$changed_list"
|
||||
git -C "$ROOT_DIR" diff-tree --no-commit-id --root --diff-filter=DR --summary -r HEAD > "$skipped_list" || true
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
@@ -57,6 +61,10 @@ case "$MODE" in
|
||||
esac
|
||||
|
||||
if [[ ! -s "$changed_list" ]]; then
|
||||
if [[ -s "$skipped_list" ]]; then
|
||||
log "Skipping delete/rename changes for devone sync:"
|
||||
sed 's/^/[devone-sync] /' "$skipped_list"
|
||||
fi
|
||||
printf '%s\n' "$current_head" > "$STATE_FILE"
|
||||
exit 0
|
||||
fi
|
||||
@@ -67,6 +75,10 @@ destination="${REMOTE_USER}@${TARGET_HOST}:${REMOTE_PATH%/}/"
|
||||
log "Syncing changed files to $destination"
|
||||
if rsync -az --from0 --files-from="$changed_list" --relative --progress --human-readable --exclude='.git/' --exclude='.DS_Store' -e "$SSH_CMD" "$ROOT_DIR/" "$destination"; then
|
||||
printf '%s\n' "$current_head" > "$STATE_FILE"
|
||||
if [[ -s "$skipped_list" ]]; then
|
||||
log "Skipped delete/rename changes for devone sync:"
|
||||
sed 's/^/[devone-sync] /' "$skipped_list"
|
||||
fi
|
||||
log "Done: $current_head"
|
||||
else
|
||||
fail "Sync failed"
|
||||
|
||||
Reference in New Issue
Block a user