From 1cb7e4b8aaee69d86dc4a8d2bed4b39e193a08a3 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 6 Apr 2026 08:00:55 +0000 Subject: [PATCH] fix: fix: disinto init can produce duplicate keys in projects/*.toml (#269) Export actual_ops_slug from setup_ops_repo via _ACTUAL_OPS_SLUG global, then update ops_repo in the TOML in-place using Python re.sub after TOML creation or detection. Falls back to inserting after the repo line if the key is missing. This prevents duplicate TOML keys on repeated init runs. Co-Authored-By: Claude Sonnet 4.6 --- bin/disinto | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bin/disinto b/bin/disinto index 4d27e38..ece30cb 100755 --- a/bin/disinto +++ b/bin/disinto @@ -1216,6 +1216,9 @@ OPSEOF fi fi fi + + # Export resolved slug for the caller to write back to the project TOML + _ACTUAL_OPS_SLUG="${actual_ops_slug}" } # Push local clone to the Forgejo remote. @@ -2145,6 +2148,24 @@ p.write_text(text) echo "Created: ${toml_path}" fi + # Update ops_repo in TOML with the resolved actual ops slug. + # Uses in-place substitution to prevent duplicate keys on repeated init runs. + # If the key is missing (manually created TOML), it is inserted after the repo line. + if [ -n "${_ACTUAL_OPS_SLUG:-}" ] && [ -f "$toml_path" ]; then + python3 -c " +import sys, re, pathlib +p = pathlib.Path(sys.argv[1]) +text = p.read_text() +new_val = 'ops_repo = \"' + sys.argv[2] + '\"' +if re.search(r'^ops_repo\s*=', text, re.MULTILINE): + text = re.sub(r'^ops_repo\s*=\s*.*\$', new_val, text, flags=re.MULTILINE) +else: + text = re.sub(r'^(repo\s*=\s*\"[^\"]*\")', r'\1\n' + new_val, text, flags=re.MULTILINE) +p.write_text(text) +" "$toml_path" "${_ACTUAL_OPS_SLUG}" + echo "Updated: ops_repo in ${toml_path}" + fi + # Create OAuth2 app on Forgejo for Woodpecker (before compose up) _WP_REPO_ID="" create_woodpecker_oauth "$forge_url" "$forge_repo"