Skip to content

feat: add land command for merging stacked PRs#28

Merged
luqven merged 4 commits intomasterfrom
feat/land-command
Dec 29, 2025
Merged

feat: add land command for merging stacked PRs#28
luqven merged 4 commits intomasterfrom
feat/land-command

Conversation

@luqven
Copy link
Owner

@luqven luqven commented Dec 29, 2025

Summary

Adds a new land subcommand that intelligently merges a stack of PRs using the spr/Graphite optimization pattern, plus automatic repository detection from git remotes.

How it works

  1. Finds the topmost PR where all PRs below it are approved
  2. Updates that PR's base to the target branch (main/master)
  3. Squash-merges that single PR (contains all commits from the stack)
  4. Closes all PRs below it with a "Landed via #N" comment

Usage

# Auto-detects repository from git remote - no -r flag needed!
gh-stack land PROJ-123

# Preview what would happen
gh-stack land PROJ-123 --dry-run

# Skip approval checks
gh-stack land PROJ-123 --no-approval

# Only land bottom 2 PRs
gh-stack land PROJ-123 --count 2

# Use a different remote (default: origin)
gh-stack land PROJ-123 --origin upstream

# Override auto-detection with explicit repo
gh-stack land PROJ-123 -r owner/repo

Features

Land Command

  • --dry-run: Preview what would happen without making changes
  • --no-approval: Skip approval requirement check
  • --count N: Only land bottom N PRs in the stack
  • Draft PRs block landing of PRs above them
  • Clear error messages with hints for resolution

Auto-detect Repository (NEW)

  • Automatically detects owner/repo from git remote URL
  • Works with SSH and HTTPS URLs (including GitHub Enterprise)
  • Fallback chain: -r flag → GHSTACK_TARGET_REPOSITORY env var → auto-detect
  • --origin / -o flag to specify which remote to use (defaults to "origin")
  • Prints detection message: Detected repository: owner/repo (from origin remote)
  • Applied to all commands: annotate, log, autorebase, land

Changes

  • New src/land.rs module with landing logic
  • New src/api/land.rs module with GitHub API methods for merge/close/update
  • Added land subcommand to CLI in main.rs
  • Added parse_github_remote_url() and detect_repo_from_remote() in src/tree.rs
  • Added resolve_repository() helper with fallback chain in main.rs
  • Added --origin flag to annotate, log, autorebase, and land commands
  • Added serial_test dev dependency for API mock tests
  • 9 new unit tests for land planning logic
  • 9 new unit tests for URL parsing
  • 3 new integration tests for API methods

Add a new 'land' subcommand that intelligently merges a stack of PRs:
- Finds the topmost PR where all PRs below it are approved
- Updates that PR's base to the target branch (main/master)
- Squash-merges that single PR (contains all commits from the stack)
- Closes all PRs below it with a 'Landed via #N' comment

Features:
- --dry-run: Preview what would happen without making changes
- --no-approval: Skip approval requirement check
- --count N: Only land bottom N PRs in the stack
- Draft PRs block landing of PRs above them

This follows the spr/Graphite optimization pattern for efficient stack landing.
Add automatic repository detection from git remote URL, eliminating the
need to pass -r flag or set GHSTACK_TARGET_REPOSITORY when running from
inside a git repository.

Changes:
- Add parse_github_remote_url() to parse SSH/HTTPS URLs (including GitHub Enterprise)
- Add detect_repo_from_remote() to extract owner/repo from git remote
- Add resolve_repository() helper with fallback chain: -r flag -> env var -> auto-detect
- Add --origin/-o flag to specify which remote to use (defaults to 'origin')
- Update annotate, log, autorebase, and land commands to use auto-detection
- Add unit tests for URL parsing
@luqven luqven merged commit 76c06b2 into master Dec 29, 2025
1 check passed
@luqven luqven deleted the feat/land-command branch December 29, 2025 16:23
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