From c2ee446009a4709d198d777b8705b9401613b2dd Mon Sep 17 00:00:00 2001 From: eiszazel Date: Wed, 14 Jan 2026 16:49:50 -0500 Subject: [PATCH] Fix setup.sh failures and improve user experience (#6) Five improvements to the setup wizard: 1. Relative path handling: Convert relative paths to absolute paths after user input to prevent failures when `claude init` changes the working directory. 2. Git push error handling: Detect actual branch name and show real errors instead of suppressing them and falling back to non-existent `master`. 3. Interactive push recovery: When push fails (e.g., remote has existing content), offer interactive options: force push with confirmation, or skip with manual command. 4. GitHub Actions setup after failed push: Only copy workflow files if push succeeds to avoid confusion. 5. OAuth token setup guidance: Replace cryptic "Remember to add CLAUDE_CODE_OAUTH_TOKEN" with: - Step-by-step instructions - Direct link to token documentation - Link to repository secrets page - Option to open setup page in browser Co-authored-by: eiszazel Co-authored-by: Claude Opus 4.5 --- scripts/setup.sh | 82 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index d6147a4..6b15790 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -80,6 +80,11 @@ VAULT_PATH=${VAULT_PATH:-$DEFAULT_VAULT} # Expand tilde if present VAULT_PATH="${VAULT_PATH/#\~/$HOME}" +# Convert to absolute path if relative +if [[ "$VAULT_PATH" != /* ]]; then + VAULT_PATH="$(pwd)/$VAULT_PATH" +fi + # Check if directory exists if [ -d "$VAULT_PATH" ]; then print_warning "Directory already exists: $VAULT_PATH" @@ -180,16 +185,77 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then read -p "Push to GitHub now? (y/n): " -n 1 -r echo + PUSH_SUCCESS=false if [[ $REPLY =~ ^[Yy]$ ]]; then - git push -u origin main 2>/dev/null || git push -u origin master - print_success "Pushed to GitHub" + # Get current branch name + CURRENT_BRANCH=$(git branch --show-current) + if git push -u origin "$CURRENT_BRANCH" 2>&1; then + print_success "Pushed to GitHub" + PUSH_SUCCESS=true + else + print_warning "Push failed - the remote repository may already have content" + echo "" + echo "How would you like to proceed?" + echo " 1) Force push (overwrites remote content - use for fresh vault repos)" + echo " 2) Skip (push manually later)" + read -p "Choose [1/2]: " -n 1 -r PUSH_CHOICE + echo "" + + case $PUSH_CHOICE in + 1) + print_warning "Force pushing will overwrite any existing content in the remote repository" + read -p "Are you sure? (y/n): " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + if git push -u origin "$CURRENT_BRANCH" --force; then + print_success "Force pushed to GitHub" + PUSH_SUCCESS=true + else + print_error "Force push failed" + fi + else + print_info "Skipping push" + fi + ;; + *) + print_info "Skipping push. You can push manually later with:" + echo " cd \"$VAULT_PATH\" && git push -u origin $CURRENT_BRANCH" + ;; + esac + fi + fi + + # Set up GitHub Action only if push succeeded + if [ "$PUSH_SUCCESS" = true ]; then + mkdir -p "$VAULT_PATH/.github/workflows" + cp "$SCRIPT_DIR/../github-actions/claude.yml" "$VAULT_PATH/.github/workflows/" + print_success "GitHub Action workflow copied" + + echo "" + print_warning "GitHub Actions requires a Claude Code OAuth token to work" + echo "" + echo "To set up the token:" + echo " 1. Get your token from: https://code.claude.com/docs/en/github-actions" + echo " 2. Go to your repo: $GITHUB_URL/settings/secrets/actions" + echo " 3. Click 'New repository secret'" + echo " 4. Name: CLAUDE_CODE_OAUTH_TOKEN" + echo " 5. Value: [paste your token]" + echo "" + + # Offer to open the setup page + read -p "Open token setup page in browser? (y/n): " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + TOKEN_URL="https://code.claude.com/docs/en/github-actions" + if command_exists xdg-open; then + xdg-open "$TOKEN_URL" 2>/dev/null || print_info "Visit: $TOKEN_URL" + elif command_exists open; then + open "$TOKEN_URL" 2>/dev/null || print_info "Visit: $TOKEN_URL" + else + print_info "Visit: $TOKEN_URL" + fi + fi fi - - # Set up GitHub Action - mkdir -p "$VAULT_PATH/.github/workflows" - cp "$SCRIPT_DIR/../github-actions/claude.yml" "$VAULT_PATH/.github/workflows/" - print_success "GitHub Action workflow copied" - print_warning "Remember to add CLAUDE_CODE_OAUTH_TOKEN to repository secrets" fi fi