From d3a2521442c42e61f138440330e63781912cc032 Mon Sep 17 00:00:00 2001 From: Reza Rezvani Date: Fri, 7 Nov 2025 03:06:29 +0100 Subject: [PATCH] fix(wizard): detect and update git remote from template to user repository MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem When users clone the blueprint template and run the wizard, git remote still points to the template repository (alirezarezvani/claude-code-github-workflow). This causes: - Permission denied when pushing (can't push to template) - Secrets set on wrong repository - Workflows run on template instead of user's project - Users unable to actually use the blueprint ## Solution Added automatic git remote detection and update in setup wizard: **1. Setup Wizard Enhancement** (setup/wizard.sh) - New function: update_git_remote() (Step 1.5) - Detects if git remote points to template repository - Prompts user for their repository owner/name - Updates git remote to user's repository - Validates the change was successful - Updates REPO_OWNER and REPO_NAME variables - Exits if user declines update (must fix manually) **2. Validation Script Enhancement** (setup/validate.sh) - New validation: validate_git_remote() (Section 0) - Checks git remote configuration before other checks - Fails validation if still pointing to template - Provides clear error message and fix instructions - Shows current vs expected remote URL **3. Documentation Updates** - QUICK_START.md: Added note about cloning to own repository - COMPLETE_SETUP.md: Added Step 1.5 "Configure Git Remote" - Both docs explain why this matters and how to fix ## Impact - ✅ Users guided to set up correctly from the start - ✅ Clear error messages if remote not updated - ✅ Validation catches this issue before other failures - ✅ Automatic fix via wizard (asks user for repo details) - ✅ Manual fix instructions provided if user declines ## Testing - Wizard prompts for repository when template remote detected - Wizard skips update when remote already correct - Validation script catches template remote - Documentation provides clear instructions Fixes critical setup issue where users couldn't actually use the blueprint. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- docs/COMPLETE_SETUP.md | 30 +++++++++++++ docs/QUICK_START.md | 12 +++++- setup/validate.sh | 49 +++++++++++++++++++++ setup/wizard.sh | 97 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 186 insertions(+), 2 deletions(-) diff --git a/docs/COMPLETE_SETUP.md b/docs/COMPLETE_SETUP.md index bb5ab4d..490574f 100644 --- a/docs/COMPLETE_SETUP.md +++ b/docs/COMPLETE_SETUP.md @@ -176,6 +176,36 @@ cp -r blueprint/setup/ ./setup/ rm -rf blueprint ``` +#### Step 1.5: Configure Git Remote + +**CRITICAL**: The blueprint is a template. You must use it in YOUR own repository. + +**If you cloned the template directly**: +```bash +# Check current remote +git remote get-url origin +# If it shows: https://github.com/alirezarezvani/claude-code-github-workflow.git +# You need to update it! + +# Option A: Create new GitHub repository and update remote +gh repo create my-project --public --source=. --remote=origin + +# Option B: Manually update to existing repository +git remote set-url origin https://github.com/YOUR_USERNAME/YOUR_REPO.git + +# Verify the change +git remote get-url origin +# Should show YOUR repository, not the template +``` + +**Why this matters**: +- ❌ **Wrong**: Pushing to template repository (you don't have permission) +- ✅ **Right**: Pushing to your own repository +- The setup wizard will detect and help fix this automatically + +**If you copied files to existing repository**: +- No action needed - your git remote is already correct ✅ + #### Step 2: Configure for Your Project Type **For Web Projects**: diff --git a/docs/QUICK_START.md b/docs/QUICK_START.md index 33c3241..bc832d4 100644 --- a/docs/QUICK_START.md +++ b/docs/QUICK_START.md @@ -40,7 +40,7 @@ Before you begin, ensure you have: ### Step 1: Clone and Setup -Copy this blueprint into your project: +**Important**: This blueprint is a template. You need to use it in YOUR own repository. ```bash # Option A: Add to existing repository @@ -51,11 +51,19 @@ cp -r .blueprint-temp/.claude/ . cp -r .blueprint-temp/setup/ . rm -rf .blueprint-temp -# Option B: Start new project with blueprint +# Option B: Clone template, then create your own repository git clone https://github.com/alirezarezvani/claude-code-github-workflow.git my-project cd my-project + +# Create your own GitHub repository +gh repo create my-project --public --source=. --remote=origin + +# Or manually update git remote +git remote set-url origin https://github.com/YOUR_USERNAME/YOUR_REPO.git ``` +**Note**: The setup wizard (see below) will detect if you're still pointing to the template repository and help you update it automatically. + ### Step 2: Configure Secrets Add required secrets to your repository: diff --git a/setup/validate.sh b/setup/validate.sh index 8d8e857..8dcfe47 100644 --- a/setup/validate.sh +++ b/setup/validate.sh @@ -101,6 +101,54 @@ This script validates your repository configuration. EOF } +# ───────────────────────────────────────────────────────────────── +# 0. Git Remote Validation +# ───────────────────────────────────────────────────────────────── + +validate_git_remote() { + log_section "0. Checking Git Remote Configuration" + + # Check if in git repository + if ! git rev-parse --git-dir &> /dev/null; then + log_fail "Not in a git repository" + return 1 + fi + + # Get current remote URL + local current_remote=$(git remote get-url origin 2>/dev/null || echo "") + + if [[ -z "$current_remote" ]]; then + log_fail "No git remote 'origin' configured" + log_info "Configure with: git remote add origin " + return 1 + fi + + # Check if pointing to template repository + local template_repo="alirezarezvani/claude-code-github-workflow" + + if [[ "$current_remote" == *"$template_repo"* ]]; then + log_fail "Git remote is still pointing to template repository!" + echo "" + echo -e "${RED}⚠️ CRITICAL: You are using the blueprint template repository directly!${NC}" + echo "" + echo " Current remote: $current_remote" + echo "" + echo " This will cause issues:" + echo " • Cannot push changes (permission denied)" + echo " • Secrets set on wrong repository" + echo " • Workflows run on template, not your project" + echo "" + echo " To fix, update git remote to YOUR repository:" + echo " git remote set-url origin https://github.com//.git" + echo "" + echo " Or run the setup wizard again: ./setup/wizard.sh" + echo "" + else + log_pass "Git remote configured correctly" + log_info "Remote: $current_remote" + fi +} + # ───────────────────────────────────────────────────────────────── # 1. Branch Validation # ───────────────────────────────────────────────────────────────── @@ -618,6 +666,7 @@ main() { show_header # Run all validation checks + validate_git_remote validate_branches validate_secrets validate_workflows diff --git a/setup/wizard.sh b/setup/wizard.sh index 583588c..621008e 100755 --- a/setup/wizard.sh +++ b/setup/wizard.sh @@ -190,6 +190,100 @@ check_prerequisites() { return 0 } +# ───────────────────────────────────────────────────────────────── +# Step 1.5: Repository Remote Setup +# ───────────────────────────────────────────────────────────────── + +update_git_remote() { + log_step "Step 1.5: Repository Remote Setup" + + # Get current remote URL + local current_remote=$(git remote get-url origin 2>/dev/null || echo "") + + if [[ -z "$current_remote" ]]; then + log_error "No git remote 'origin' found" + log_info "This should not happen if prerequisites passed" + return 1 + fi + + log_info "Current remote: $current_remote" + + # Check if pointing to template repository + local template_repo="alirezarezvani/claude-code-github-workflow" + + if [[ "$current_remote" == *"$template_repo"* ]]; then + log_warning "Git remote is still pointing to the template repository!" + echo "" + echo "⚠️ You need to update the remote URL to YOUR repository." + echo "" + echo "This blueprint is a template - you should be using it in YOUR" + echo "own repository, not the original template repository." + echo "" + + # Prompt for user's repository + echo "📋 Please provide your GitHub repository information:" + echo "" + + local user_owner="" + local user_repo="" + + while [[ -z "$user_owner" ]]; do + read -p "$(echo -e "${YELLOW}?${NC} Repository owner (your username or org): ")" user_owner + if [[ -z "$user_owner" ]]; then + log_error "Repository owner cannot be empty" + fi + done + + while [[ -z "$user_repo" ]]; do + read -p "$(echo -e "${YELLOW}?${NC} Repository name: ")" user_repo + if [[ -z "$user_repo" ]]; then + log_error "Repository name cannot be empty" + fi + done + + # Construct new remote URL (using HTTPS) + local new_remote="https://github.com/$user_owner/$user_repo.git" + + echo "" + log_info "New remote URL: $new_remote" + echo "" + + if ! confirm "Update git remote to this URL?"; then + log_warning "Git remote not updated." + echo "" + log_error "You MUST update the git remote before proceeding!" + echo "" + echo "To update manually, run:" + echo " git remote set-url origin https://github.com//.git" + echo "" + echo "Then run this wizard again." + return 1 + fi + + # Update remote URL + if git remote set-url origin "$new_remote"; then + log "Git remote updated successfully!" + + # Verify the change + local updated_remote=$(git remote get-url origin) + log_info "Verified remote: $updated_remote" + + # Update global variables + REPO_OWNER="$user_owner" + REPO_NAME="$user_repo" + else + log_error "Failed to update git remote" + return 1 + fi + else + log "Git remote is already configured correctly" + log_info "Remote: $current_remote" + fi + + echo "" + return 0 +} + # ───────────────────────────────────────────────────────────────── # Step 2: Detect Project Type # ───────────────────────────────────────────────────────────────── @@ -966,6 +1060,9 @@ main() { # Step 1: Check prerequisites check_prerequisites || exit 1 + # Step 1.5: Update git remote if needed + update_git_remote || exit 1 + # Step 2: Detect project type detect_project_type