From f92efd2fcfe1b9f5b27b7e5917c49c400590e7af Mon Sep 17 00:00:00 2001 From: openhands Date: Sun, 22 Mar 2026 15:40:49 +0000 Subject: [PATCH 1/2] fix: fix: disinto init fails when projects/.toml already exists in repo (#559) When projects/.toml already exists (e.g. committed from another box), skip TOML generation and continue with remaining setup steps (clone repo, create labels, install cron). Reads repo_root and branch from the existing TOML. If --repo-root flag differs from TOML value, prompts to update it. Co-Authored-By: Claude Opus 4.6 (1M context) --- bin/disinto | 61 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/bin/disinto b/bin/disinto index 6e7005a..aa03dc2 100755 --- a/bin/disinto +++ b/bin/disinto @@ -263,15 +263,52 @@ disinto_init() { echo "Name: ${project_name}" # Check for existing config + local toml_exists=false if [ -f "$toml_path" ]; then - echo "Error: ${toml_path} already exists" >&2 - exit 1 + toml_exists=true + echo "Config: ${toml_path} (already exists, reusing)" + + # Read repo_root and branch from existing TOML + local existing_root existing_branch + existing_root=$(python3 -c " +import sys, tomllib +with open(sys.argv[1], 'rb') as f: + cfg = tomllib.load(f) +print(cfg.get('repo_root', '')) +" "$toml_path" 2>/dev/null) || existing_root="" + existing_branch=$(python3 -c " +import sys, tomllib +with open(sys.argv[1], 'rb') as f: + cfg = tomllib.load(f) +print(cfg.get('primary_branch', '')) +" "$toml_path" 2>/dev/null) || existing_branch="" + + # Use existing values as defaults + if [ -n "$existing_branch" ] && [ -z "$branch" ]; then + branch="$existing_branch" + fi + + # Handle repo_root: flag overrides TOML, prompt if they differ + if [ -z "$repo_root" ]; then + repo_root="${existing_root:-/home/${USER}/${project_name}}" + elif [ -n "$existing_root" ] && [ "$repo_root" != "$existing_root" ]; then + echo "Note: --repo-root (${repo_root}) differs from TOML (${existing_root})" + if [ "$auto_yes" = false ] && [ -t 0 ]; then + read -rp "Update repo_root in TOML to ${repo_root}? [y/N] " confirm + if [[ "$confirm" =~ ^[Yy] ]]; then + sed -i "s|^repo_root.*=.*|repo_root = \"${repo_root}\"|" "$toml_path" + echo "Updated: repo_root in ${toml_path}" + else + repo_root="$existing_root" + fi + fi + fi fi # Validate tokens validate_env - # Determine repo root + # Determine repo root (for new projects) repo_root="${repo_root:-/home/${USER}/${project_name}}" # Clone or validate @@ -283,15 +320,17 @@ disinto_init() { fi echo "Branch: ${branch}" - # Prompt for CI ID if interactive and not already set via flag - if [ "$ci_id" = "0" ] && [ "$auto_yes" = false ] && [ -t 0 ]; then - read -rp "Woodpecker CI repo ID (0 to skip CI): " user_ci_id - ci_id="${user_ci_id:-0}" - fi + # Generate project TOML (skip if already exists) + if [ "$toml_exists" = false ]; then + # Prompt for CI ID if interactive and not already set via flag + if [ "$ci_id" = "0" ] && [ "$auto_yes" = false ] && [ -t 0 ]; then + read -rp "Woodpecker CI repo ID (0 to skip CI): " user_ci_id + ci_id="${user_ci_id:-0}" + fi - # Generate project TOML - generate_toml "$toml_path" "$project_name" "$codeberg_repo" "$repo_root" "$branch" "$ci_id" - echo "Created: ${toml_path}" + generate_toml "$toml_path" "$project_name" "$codeberg_repo" "$repo_root" "$branch" "$ci_id" + echo "Created: ${toml_path}" + fi # Create labels on remote create_labels "$codeberg_repo" From a03c277f8d9860c8a091ebb8695d021edfd32281 Mon Sep 17 00:00:00 2001 From: openhands Date: Sun, 22 Mar 2026 15:54:35 +0000 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20address=20review=20=E2=80=94=20auto-?= =?UTF-8?q?update=20TOML=20in=20--yes=20mode,=20use=20python3=20for=20safe?= =?UTF-8?q?=20write?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - When --yes is passed with a differing --repo-root, auto-apply the TOML update instead of silently skipping. Prevents stale repo_root in TOML. - Replace sed with python3+re for updating repo_root to avoid delimiter injection from user-supplied paths. Co-Authored-By: Claude Opus 4.6 (1M context) --- bin/disinto | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bin/disinto b/bin/disinto index aa03dc2..4849b01 100755 --- a/bin/disinto +++ b/bin/disinto @@ -293,15 +293,27 @@ print(cfg.get('primary_branch', '')) repo_root="${existing_root:-/home/${USER}/${project_name}}" elif [ -n "$existing_root" ] && [ "$repo_root" != "$existing_root" ]; then echo "Note: --repo-root (${repo_root}) differs from TOML (${existing_root})" - if [ "$auto_yes" = false ] && [ -t 0 ]; then + local update_toml=false + if [ "$auto_yes" = true ]; then + update_toml=true + elif [ -t 0 ]; then read -rp "Update repo_root in TOML to ${repo_root}? [y/N] " confirm if [[ "$confirm" =~ ^[Yy] ]]; then - sed -i "s|^repo_root.*=.*|repo_root = \"${repo_root}\"|" "$toml_path" - echo "Updated: repo_root in ${toml_path}" + update_toml=true else repo_root="$existing_root" fi fi + if [ "$update_toml" = true ]; then + python3 -c " +import sys, re, pathlib +p = pathlib.Path(sys.argv[1]) +text = p.read_text() +text = re.sub(r'^repo_root\s*=\s*.*$', 'repo_root = \"' + sys.argv[2] + '\"', text, flags=re.MULTILINE) +p.write_text(text) +" "$toml_path" "$repo_root" + echo "Updated: repo_root in ${toml_path}" + fi fi fi