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?
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:
Usage:
Does this make sense as a Worktrunk composition, or am I missing a simpler or safer approach?
In particular:
wt removeexpected to recognize the branch as integrated after a squash merge?ghandgitplumbing?