diff options
| -rw-r--r-- | pkgs/claude-inbox.nix | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/pkgs/claude-inbox.nix b/pkgs/claude-inbox.nix index 9cac711..f75faa4 100644 --- a/pkgs/claude-inbox.nix +++ b/pkgs/claude-inbox.nix @@ -35,14 +35,15 @@ let BRANCH is seen); --diff: the diff to BRANCH from WHAT (any branch or commit), by default from HEAD; without BRANCH, REPO's branches, as a graph. Fetches first: REPO, or without it, all of DIR's. - --take BRANCH [-f|--force|--pick]: fast-forward master (it has to be - checked out) to BRANCH, as last fetched (i.e. as shown), 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; --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. + --take BRANCH [-f|--force|--pick]: fast-forward master to BRANCH, as + last fetched (i.e. as shown), and push it to claude; --force: rename + master to abandoned/master-DATE, make BRANCH master (with the old + one's upstream), and push it 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. master: checked out, or not at all + (not in another worktree); --pick needs it checked out. --push REPO [-f|--force]: master to claude; --force for a rewritten master, but only while claude's is still the one last fetched (--force-with-lease). Both push master to claude's master, and give @@ -302,8 +303,16 @@ let fi ;; take) - test "$(git -C "$r" symbolic-ref -q --short HEAD)" = master || - die "$name: master isn't checked out" + # master, checked out here, or nowhere (then it'll do without a + # working tree, but --pick can't), but not in another worktree + if test "$(git -C "$r" symbolic-ref -q --short HEAD)" = master; then + here=1 + elif git -C "$r" worktree list --porcelain | grep -qx 'branch refs/heads/master'; then + die "$name: master is checked out in another worktree (git worktree list)" + else + here= + test -z "$pick" || die "$name: --pick needs master checked out" + fi if test -n "$force"; then # master, renamed, and a new one, of BRANCH, with the old one's # upstream (which the rename took along) @@ -317,7 +326,9 @@ let old=$old$s up=$(git -C "$r" rev-parse -q --verify --abbrev-ref 'master@{upstream}' 2>/dev/null || :) git -C "$r" branch -m master "$old" - if ! git -C "$r" switch -q --no-track -c master "claude/$b"; then + if test -z "$here"; then + git -C "$r" branch -q --no-track master "claude/$b" + elif ! git -C "$r" switch -q --no-track -c master "claude/$b"; then git -C "$r" branch -m "$old" master die "$name: can't check out $b as master (uncommitted changes in the way?)" fi @@ -336,8 +347,14 @@ let die "$name: stopped picking $b (resolve, git cherry-pick --continue, then claude-inbox $name --push; or git cherry-pick --abort)" push_master else - git -C "$r" -c advice.diverging=false merge --ff-only "claude/$b" || - die "$name: $b isn't master and more (--take --pick, or --force)" + if test -z "$here"; then + # fetching into a branch that isn't checked out: fast-forwards only + git -C "$r" fetch -q . "refs/remotes/claude/$b:refs/heads/master" || + die "$name: $b isn't master and more (--take --force; or check out master, for --pick)" + else + git -C "$r" -c advice.diverging=false merge --ff-only "claude/$b" || + die "$name: $b isn't master and more (--take --pick, or --force)" + fi push_master fi seen "$b" |
