fix: clean stale OpenTofu lock before repo sync

This commit is contained in:
juvenal.diaz 2026-10-27 13:26:45 -06:00
parent 8c17723c9c
commit b998b5bbab
1 changed files with 8 additions and 0 deletions

View File

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