Merge pull request 'fix: fix: disinto init fails when projects/<name>.toml already exists in repo (#559)' (#562) from fix/issue-559 into main
This commit is contained in:
commit
005a39237e
1 changed files with 62 additions and 11 deletions
73
bin/disinto
73
bin/disinto
|
|
@ -263,15 +263,64 @@ disinto_init() {
|
||||||
echo "Name: ${project_name}"
|
echo "Name: ${project_name}"
|
||||||
|
|
||||||
# Check for existing config
|
# Check for existing config
|
||||||
|
local toml_exists=false
|
||||||
if [ -f "$toml_path" ]; then
|
if [ -f "$toml_path" ]; then
|
||||||
echo "Error: ${toml_path} already exists" >&2
|
toml_exists=true
|
||||||
exit 1
|
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})"
|
||||||
|
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
|
||||||
|
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
|
fi
|
||||||
|
|
||||||
# Validate tokens
|
# Validate tokens
|
||||||
validate_env
|
validate_env
|
||||||
|
|
||||||
# Determine repo root
|
# Determine repo root (for new projects)
|
||||||
repo_root="${repo_root:-/home/${USER}/${project_name}}"
|
repo_root="${repo_root:-/home/${USER}/${project_name}}"
|
||||||
|
|
||||||
# Clone or validate
|
# Clone or validate
|
||||||
|
|
@ -283,15 +332,17 @@ disinto_init() {
|
||||||
fi
|
fi
|
||||||
echo "Branch: ${branch}"
|
echo "Branch: ${branch}"
|
||||||
|
|
||||||
# Prompt for CI ID if interactive and not already set via flag
|
# Generate project TOML (skip if already exists)
|
||||||
if [ "$ci_id" = "0" ] && [ "$auto_yes" = false ] && [ -t 0 ]; then
|
if [ "$toml_exists" = false ]; then
|
||||||
read -rp "Woodpecker CI repo ID (0 to skip CI): " user_ci_id
|
# Prompt for CI ID if interactive and not already set via flag
|
||||||
ci_id="${user_ci_id:-0}"
|
if [ "$ci_id" = "0" ] && [ "$auto_yes" = false ] && [ -t 0 ]; then
|
||||||
fi
|
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"
|
||||||
generate_toml "$toml_path" "$project_name" "$codeberg_repo" "$repo_root" "$branch" "$ci_id"
|
echo "Created: ${toml_path}"
|
||||||
echo "Created: ${toml_path}"
|
fi
|
||||||
|
|
||||||
# Create labels on remote
|
# Create labels on remote
|
||||||
create_labels "$codeberg_repo"
|
create_labels "$codeberg_repo"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue