From b998b5bbab82abe17aca3f8562ce4a67e913f21c Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Tue, 27 Oct 2026 13:26:45 -0600 Subject: [PATCH] fix: clean stale OpenTofu lock before repo sync --- scripts/repo-sync | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/repo-sync b/scripts/repo-sync index 2d4dd64..f7bc7ab 100755 --- a/scripts/repo-sync +++ b/scripts/repo-sync @@ -22,6 +22,14 @@ current_branch="$("${git_cmd[@]}" branch --show-current)" echo "Git remote not found: ${remote}" >&2 exit 2 } +# OpenTofu leaves this transient lock metadata after an interrupted plan. It +# is safe to remove only when no OpenTofu process is still running; real source +# changes remain blocking as before. +stale_tofu_lock="${repo_root}/bootstrap/oci/.terraform.tfstate.lock.info" +if [[ -f "${stale_tofu_lock}" ]] && ! pgrep -af '[t]ofu' >/dev/null 2>&1; then + rm -f "${stale_tofu_lock}" + echo "Removed stale OpenTofu lock metadata: ${stale_tofu_lock}" +fi if [[ -n "$("${git_cmd[@]}" status --porcelain)" ]]; then echo "Refusing repo sync: working tree is not clean." >&2 "${git_cmd[@]}" status --short >&2