Skip to content

Improve create and init workflows#5

Merged
ryan-williams merged 6 commits intomainfrom
rw/init
Nov 8, 2025
Merged

Improve create and init workflows#5
ryan-williams merged 6 commits intomainfrom
rw/init

Conversation

@ryan-williams
Copy link
Copy Markdown
Member

@ryan-williams ryan-williams commented Nov 8, 2025

This PR includes several improvements to the create and init commands, making the PR/Issue creation workflow more robust and user-friendly.

Key Changes

Template and Workflow

  1. Remove placeholder confusion - Templates now use plain # Title format; link-references added automatically after PR/Issue creation
  2. Interactive web editor support - Default mode opens browser, waits for user confirmation, then fetches PR info and updates file

create Command Improvements

  1. Support user-namespaced branches - Auto-detects remote branch names when local branch differs (e.g., local ws3 → remote m/rw/ws3)
  2. Better parent repo detection - Uses git rev-parse --show-toplevel to properly find parent repo when running from nested gh/new/ directory
  3. Flexible opening behavior - New -y/--yes count flag:
    • Default (no flag): Opens web editor during creation (interactive, waits for Enter)
    • -y once: Creates PR then views result
    • -yy twice: Creates silently without opening

init Command Improvements

  1. Complete workflow setup - Creates initial commit and configures gist mirror automatically, eliminating manual force-push
  2. Plain template - No more [owner/repo#XXXX] placeholders to confuse users

Commits

  • Fix create to use remote branch name for PRs
  • Fix create to use git to find parent repo root
  • Add -y/--yes count flag to control opening behavior in create
  • Fix placeholder link handling in create
  • Make init create initial commit and set up gist mirror
  • Remove placeholder format, use plain titles until PR created

- Auto-detect remote tracking branch instead of local branch name
- Strip remote prefix (e.g., `m/rw/ws3` → `rw/ws3`) for GitHub PR head
- Supports user-namespaced branches (e.g., `rw/` prefix)
- Falls back to local branch name if no remote tracking branch

Fixes issue where local branch `ws3` pushed to remote as `m/rw/ws3` would fail PR creation with "Head ref must be a branch" error.
- Go up one level from current directory
- Use `git rev-parse --show-toplevel` to find repo root (instead of manual directory walking)
- Properly detects parent repo from `gh/new/` nested git repos

Fixes head branch auto-detection from `gh/new/` subdirectories.
- Default (no flag): Open web editor during creation (interactive mode)
- `-y` once: Skip web editor, create then open result for viewing
- `-y -y` or `-yy`: Skip all, create silently without opening

Replaces previous `-w/--web` boolean flag with more flexible count-based approach.
Updates all tests to use `yes=2` (create silently) instead of `web=False`.
**Bug 1: Title not stripped**
- `read_description_file()` now strips placeholder prefixes like `[owner/repo#XXXX]` or `[owner/repo#NUMBER]` from titles
- Prevents double-prefixing like `# [owner/repo#1967] [owner/repo#XXXX] Title`

**Bug 2: Placeholder link definitions not removed**
- `write_description_with_link_ref()` now removes placeholder link definitions (e.g., `[owner/repo#XXXX]:`) before adding the real one
- Cleans up leftover placeholders from template

Fixes issues where `ghpr create` would mangle titles and leave unused link definitions.
**New behavior:**
- Creates DESCRIPTION.md with proper link-ref template (including `[owner/repo#XXXX]` placeholder)
- Makes initial git commit
- Creates public gist and adds as 'g' remote
- Sets up main branch to track g/main
- Force pushes to replace gist's orphan commit with local history

**Benefits:**
- Complete setup in one command
- No orphan gist commits requiring force push
- Gist ready to use immediately with `ghpr push`

**Next steps** (shown to user):
- `cd gh/new`
- Edit DESCRIPTION.md
- `git commit -am 'Update PR description'`
- `ghpr create`
- Templates now use plain `# Title` format (no placeholders)
- `create` reads plain format, creates PR/Issue, then updates file with link-reference format
- Web editor mode waits for user to press Enter, then fetches PR info
- `read_description_file()` now has `expect_plain` flag for pre/post-creation formats
- Backward compatible: still handles old placeholder format when reading existing files
@ryan-williams ryan-williams merged commit 0e907f9 into main Nov 8, 2025
6 checks passed
@ryan-williams ryan-williams deleted the rw/init branch November 8, 2025 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant