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