Skip to content

Is this wt land [PR] alias a sound pattern? #3735

Description

@mavam

I wanted a single command that squash-merges a GitHub PR, updates the local default branch, and removes the corresponding worktree.

I ended up with this alias:

[[aliases.land]]
merge-pr = '''
{% if args | length == 0 %}
gh pr merge --squash --match-head-commit {{ commit }}
{% elif args | length == 1 %}
gh pr merge {{ args[0] }} --squash --match-head-commit "$(gh pr view {{ args[0] }} --json headRefOid --jq .headRefOid)"
{% else %}
echo "usage: wt land [PR]" >&2; exit 2
{% endif %}
'''

[[aliases.land]]
sync-main = "git -C {{ worktree_path_of_branch(default_branch) }} pull --ff-only --prune {{ remote }} {{ default_branch }}"

[[aliases.land]]
cleanup = '''
{% if args | length == 0 %}
wt remove {{ branch }}
{% else %}
branch="$(gh pr view {{ args[0] }} --json headRefName --jq .headRefName)"
if git show-ref --verify --quiet "refs/heads/$branch"; then
  wt remove "$branch"
fi
{% endif %}
'''

Usage:

wt land       # From the PR worktree
wt land 36    # From main or another worktree

Does this make sense as a Worktrunk composition, or am I missing a simpler or safer approach?

In particular:

  • Is wt remove expected to recognize the branch as integrated after a squash merge?
  • Is resolving the PR head branch after merging sufficiently robust?
  • Are there Worktrunk primitives that would avoid the explicit gh and git plumbing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions