summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-21 21:16:54 +0000
committertv <tv@krebsco.de>2026-11-21 21:29:02 +0000
commitde94bcca581de95c7edff9f8febbde115ba7e11c (patch)
treedf3fe7b72b870f22de0ee2dd5aeae906e92cdf71
parent7b6887a5d327036861853c615ba2d9a3127e5833 (diff)
pkgs/claude-inbox: take --pick, for a branch behind master
The commits of BRANCH that master doesn't have yet (git cherry's +, so rebased ones master has are left out) get cherry-picked onto master, which is then pushed, like take. On a conflict, it stops there, on master: resolve, git cherry-pick --continue, then push; or --abort. Until then, push refuses: master has only some of the picks.
-rw-r--r--pkgs/claude-inbox.nix40
1 files changed, 32 insertions, 8 deletions
diff --git a/pkgs/claude-inbox.nix b/pkgs/claude-inbox.nix
index 5920440..bd134b3 100644
--- a/pkgs/claude-inbox.nix
+++ b/pkgs/claude-inbox.nix
@@ -18,7 +18,7 @@ let
usage: claude-inbox [OPTION...] [list]
claude-inbox [OPTION...] [--] REPO [list]
claude-inbox [OPTION...] [--] REPO show [BRANCH [--diff[=WHAT]]]
- claude-inbox [OPTION...] [--] REPO take [-f|--force] BRANCH
+ claude-inbox [OPTION...] [--] REPO take [-f|--force|--pick] BRANCH
claude-inbox [OPTION...] [--] REPO push [-f|--force]
OPTION: -d DIR, --vm HOST, --no-fetch, --by-remote.
list (the default) fetches the repositories the VM has (ssh HOST: its
@@ -37,12 +37,15 @@ let
take: fast-forward master (it has to be checked out) to BRANCH, and
push it to claude; --force: rename master to abandoned/master-DATE,
check out BRANCH as master (with the old one's upstream), and push it
- like push --force.
+ like push --force; --pick: put the commits of BRANCH that master
+ doesn't have yet (by content) on top of it, one by one (a rebase,
+ but onto master, and on it: on a conflict, it stops there, to resolve
+ and git cherry-pick --continue, then push, or --abort), and push it.
push: master to claude; --force for a rewritten master, but only
while claude's is still the one last fetched (--force-with-lease).
DIR: $CLAUDE_INBOX_SRC, or ~/sync/src; HOST: $CLAUDE_INBOX_VM, or claude.
- Options of a command (-f, --diff) can go anywhere after it. -- takes
- the next word for REPO, even list or help.
+ Options of a command (-f, --pick, --diff) can go anywhere after it.
+ -- takes the next word for REPO, even list or help.
EOF
}
die() {
@@ -91,14 +94,17 @@ let
seen() {
git -C "$r" update-ref "refs/claude-seen/$1" "refs/remotes/claude/$1"
}
- # the command's own options (-f, --diff) anywhere among its arguments
+ # the command's own options (-f, --pick, --diff) anywhere among its
+ # arguments
force=
+ pick=
diff=
what=
args=()
for a; do
case $cmd:$a in
take:-f | take:--force | push:-f | push:--force) force=1 ;;
+ take:--pick) pick=1 ;;
show:--diff) diff=1 what= ;;
show:--diff=*) diff=1 what=''${a#--diff=} ;;
*:-*) usage >&2; exit 1 ;;
@@ -214,6 +220,7 @@ let
die "$name: master isn't checked out"
git -C "$r" rev-parse -q --verify "refs/remotes/claude/$b" >/dev/null ||
die "$name: claude has no branch $b"
+ test -z "$force" || test -z "$pick" || die "take: --force or --pick, not both"
if test -n "$force"; then
# master, renamed, and a new one, of BRANCH, with the old one's
# upstream (which the rename took along)
@@ -236,9 +243,18 @@ let
fi
echo "claude-inbox: $name: master is $b now; the old one is $old"
git -C "$r" push --force-with-lease claude master
+ elif test -n "$pick"; then
+ # what git cherry calls new (+), oldest first: rebased commits
+ # that master has already are left out, as a rebase would
+ picks=$(git -C "$r" cherry master "claude/$b" | sed -n 's/^+ //p')
+ test -n "$picks" || die "$name: master has all of $b already"
+ # shellcheck disable=SC2086
+ git -C "$r" cherry-pick $picks ||
+ die "$name: stopped picking $b (resolve, git cherry-pick --continue, then claude-inbox $name push; or git cherry-pick --abort)"
+ git -C "$r" push claude master
else
git -C "$r" -c advice.diverging=false merge --ff-only "claude/$b" ||
- die "$name: $b isn't master and more (rebase it first, or take --force)"
+ die "$name: $b isn't master and more (take --pick, or --force)"
git -C "$r" push claude master
fi
seen "$b"
@@ -246,6 +262,13 @@ let
push)
test ''${#args[@]} = 0 || { usage >&2; exit 1; }
r=$(repo)
+ # not halfway through take --pick: on a conflict, master has some
+ # of the picks already (CHERRY_PICK_HEAD while it's unresolved, the
+ # sequencer for the rest)
+ if git -C "$r" rev-parse -q --verify CHERRY_PICK_HEAD >/dev/null ||
+ test -e "$(git -C "$r" rev-parse --path-format=absolute --git-path sequencer)"; then
+ die "$name: a cherry-pick is in progress (git cherry-pick --continue, or --abort)"
+ fi
git -C "$r" push ''${force:+--force-with-lease} claude master
;;
*)
@@ -309,8 +332,9 @@ let
case $cmd:''${#args[@]} in
show:0) COMPREPLY=($(compgen -W "--diff $branches" -- "$cur")) ;;
show:*) COMPREPLY=($(compgen -W "--diff" -- "$cur")) ;;
- take:0) COMPREPLY=($(compgen -W "-f --force $branches" -- "$cur")) ;;
- take:* | push:*) COMPREPLY=($(compgen -W "-f --force" -- "$cur")) ;;
+ take:0) COMPREPLY=($(compgen -W "-f --force --pick $branches" -- "$cur")) ;;
+ take:*) COMPREPLY=($(compgen -W "-f --force --pick" -- "$cur")) ;;
+ push:*) COMPREPLY=($(compgen -W "-f --force" -- "$cur")) ;;
esac
}
complete -F _claude_inbox claude-inbox