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 <eiszazel@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -80,6 +80,11 @@ VAULT_PATH=${VAULT_PATH:-$DEFAULT_VAULT}
|
|||||||
# Expand tilde if present
|
# Expand tilde if present
|
||||||
VAULT_PATH="${VAULT_PATH/#\~/$HOME}"
|
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
|
# Check if directory exists
|
||||||
if [ -d "$VAULT_PATH" ]; then
|
if [ -d "$VAULT_PATH" ]; then
|
||||||
print_warning "Directory already exists: $VAULT_PATH"
|
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
|
read -p "Push to GitHub now? (y/n): " -n 1 -r
|
||||||
echo
|
echo
|
||||||
|
PUSH_SUCCESS=false
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
git push -u origin main 2>/dev/null || git push -u origin master
|
# 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"
|
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
|
fi
|
||||||
|
|
||||||
# Set up GitHub Action
|
# Set up GitHub Action only if push succeeded
|
||||||
|
if [ "$PUSH_SUCCESS" = true ]; then
|
||||||
mkdir -p "$VAULT_PATH/.github/workflows"
|
mkdir -p "$VAULT_PATH/.github/workflows"
|
||||||
cp "$SCRIPT_DIR/../github-actions/claude.yml" "$VAULT_PATH/.github/workflows/"
|
cp "$SCRIPT_DIR/../github-actions/claude.yml" "$VAULT_PATH/.github/workflows/"
|
||||||
print_success "GitHub Action workflow copied"
|
print_success "GitHub Action workflow copied"
|
||||||
print_warning "Remember to add CLAUDE_CODE_OAUTH_TOKEN to repository secrets"
|
|
||||||
|
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
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user