Prevent devone delete sync

This commit is contained in:
sas.fajri
2026-04-23 13:53:46 +07:00
parent daff52ca4e
commit 394cc95b71
2 changed files with 17 additions and 3 deletions

View File

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