fix: address review — auto-update TOML in --yes mode, use python3 for safe write

- 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) <noreply@anthropic.com>
This commit is contained in:
openhands 2026-03-22 15:54:35 +00:00
parent f92efd2fcf
commit a03c277f8d

View file

@ -293,15 +293,27 @@ print(cfg.get('primary_branch', ''))
repo_root="${existing_root:-/home/${USER}/${project_name}}" repo_root="${existing_root:-/home/${USER}/${project_name}}"
elif [ -n "$existing_root" ] && [ "$repo_root" != "$existing_root" ]; then elif [ -n "$existing_root" ] && [ "$repo_root" != "$existing_root" ]; then
echo "Note: --repo-root (${repo_root}) differs from TOML (${existing_root})" 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 read -rp "Update repo_root in TOML to ${repo_root}? [y/N] " confirm
if [[ "$confirm" =~ ^[Yy] ]]; then if [[ "$confirm" =~ ^[Yy] ]]; then
sed -i "s|^repo_root.*=.*|repo_root = \"${repo_root}\"|" "$toml_path" update_toml=true
echo "Updated: repo_root in ${toml_path}"
else else
repo_root="$existing_root" repo_root="$existing_root"
fi fi
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
fi fi