diff options
Diffstat (limited to 'pkgs')
| -rw-r--r-- | pkgs/claude-inbox.nix | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/pkgs/claude-inbox.nix b/pkgs/claude-inbox.nix index 09eaf89..f789025 100644 --- a/pkgs/claude-inbox.nix +++ b/pkgs/claude-inbox.nix @@ -52,6 +52,14 @@ let local branch). Only with a clean working tree: nothing changed, nothing untracked, no merge, rebase, cherry-pick or revert going on. + --stack=BRANCH (or --stack BRANCH) + Fetch REPO first, then put the commits of BRANCH that HEAD + doesn't have yet (by content) on top of HEAD, one by one, + detached (no branch moves, nothing gets pushed): to try several + branches at once, one --stack after the other (e.g. after + --checkout of the first). On a conflict, it stops there: + resolve, git cherry-pick --continue; or git cherry-pick --abort. + Only with a clean working tree, as --checkout. --push [REPO] [-f|--force] Push master to claude's master (and make that master's upstream, if it has none). @@ -121,7 +129,7 @@ let local x='[^-A-Za-z0-9_]' sed -E \ -e "s/^([A-Z][A-Za-z ]*:)$/$C_HEAD\1$C_OFF/" \ - -e ":a; s/(^|$x)(--(list|show|take|push|checkout)|COMMAND)($x|$)/\1$C_CMD\2$C_OFF\4/; ta" \ + -e ":a; s/(^|$x)(--(list|show|take|push|checkout|stack)|COMMAND)($x|$)/\1$C_CMD\2$C_OFF\4/; ta" \ -e ":b; s/(^|$x)(-d|--vm|--no-fetch|--by-remote|-f|--force|--pick|--diff|--git|-h|--help|OPTION)($x|$)/\1$C_OPT\2$C_OFF\3/; tb" \ -e ":c; s/(^|$x)(REPO)($x|$)/\1$C_REPO\2$C_OFF\3/; tc" \ -e ":d; s/(^|$x)(BRANCH)($x|$)/\1$C_BRANCH\2$C_OFF\3/; td" @@ -194,10 +202,10 @@ let --vm) vm=$2; shift ;; --no-fetch) fetch= ;; --by-remote) by=remote ;; - --list | --show | --take | --push | --checkout | --checkout=*) + --list | --show | --take | --push | --checkout | --checkout=* | --stack | --stack=*) c=''${1%%=*} c=''${c#--} test -z "$cmd" || test "$cmd" = "$c" || die "--$cmd or --$c, not both" - case $1 in --checkout=*) words+=("''${1#--checkout=}") ;; esac + case $1 in --*=*) words+=("''${1#*=}") ;; esac cmd=$c ;; -f | --force) force=1 ;; --pick) pick=1 ;; @@ -302,7 +310,7 @@ let prefetch= if test -n "$fetch"; then case $cmd in - show | checkout) prefetch=1 ;; + show | checkout | stack) prefetch=1 ;; "") if test ''${#words[@]} = 2 || ! is_repo "''${words[0]}"; then prefetch=1; fi ;; esac fi @@ -333,6 +341,7 @@ let take) test -n "$b" || die "--take needs a BRANCH" test -z "$force" || test -z "$pick" || die "--take: --force or --pick, not both" ;; checkout) test -n "$b" || die "--checkout needs a BRANCH" ;; + stack) test -n "$b" || die "--stack needs a BRANCH" ;; push) test -n "$name" || repo_of_pwd || die "--push needs a REPO (or to be in one)" test -z "$b" || die "--push takes no BRANCH" ;; esac @@ -341,6 +350,18 @@ let seen() { git -C "$r" update-ref "refs/claude-seen/$1" "refs/remotes/claude/$1" } + # only with a clean working tree (--checkout, --stack): nothing + # changed, nothing untracked, no merge, rebase, cherry-pick or revert + # going on + clean_tree() { + local x + test -z "$(git -C "$r" status --porcelain)" || + die "$name: the working tree isn't clean (git status)" + for x in MERGE_HEAD CHERRY_PICK_HEAD REVERT_HEAD rebase-merge rebase-apply sequencer; do + test ! -e "$(git -C "$r" rev-parse --path-format=absolute --git-path "$x")" || + die "$name: a merge, rebase, cherry-pick or revert is going on" + done + } # master to claude's master, always; and if master has no upstream # (a new one, of take --force, say), claude's, so @{u} works push_master() { @@ -517,17 +538,24 @@ let seen "$b" ;; checkout) - # only with a clean working tree: nothing changed, nothing - # untracked, no merge, rebase, cherry-pick or revert going on - test -z "$(git -C "$r" status --porcelain)" || - die "$name: the working tree isn't clean (git status)" - for x in MERGE_HEAD CHERRY_PICK_HEAD REVERT_HEAD rebase-merge rebase-apply sequencer; do - test ! -e "$(git -C "$r" rev-parse --path-format=absolute --git-path "$x")" || - die "$name: a merge, rebase, cherry-pick or revert is going on" - done + clean_tree git -C "$r" switch -q --detach "claude/$b" echo "claude-inbox: $name: at $b, detached: $(git -C "$r" log -1 --format='%h %s')" ;; + stack) + # BRANCH's commits that HEAD doesn't have yet (by content), on top + # of it, detached, so that no branch moves: to try several + # branches at once, stacked + clean_tree + picks=$(git -C "$r" cherry HEAD "claude/$b" | sed -n 's/^+ //p') + test -n "$picks" || die "$name: HEAD has all of $b already" + was=$(git -C "$r" log -1 --format='%h %s') + git -C "$r" symbolic-ref -q HEAD >/dev/null && git -C "$r" switch -q --detach + # shellcheck disable=SC2086 + git -C "$r" cherry-pick $picks || + die "$name: stopped stacking $b (resolve, git cherry-pick --continue; or git cherry-pick --abort, back to $was, detached)" + echo "claude-inbox: $name: $b stacked ($(wc -w <<< "$picks") commits) on $was, detached: $(git -C "$r" log -1 --format='%h %s')" + ;; push) # not halfway through take --pick: on a conflict, master has some # of the picks already (CHERRY_PICK_HEAD while it's unresolved, the @@ -559,9 +587,9 @@ let -d) src=''${COMP_WORDS[i+1]}; i=$((i + 1)) ;; --vm) i=$((i + 1)) ;; --list | --show | --take | --push) cmd=''${w#--} ;; - --checkout) - cmd=checkout - # --checkout=BRANCH: BRANCH a word, but the one at hand + --checkout | --stack) + cmd=''${w#--} + # --checkout=BRANCH (--stack=): BRANCH a word, but the one at hand if [ "''${COMP_WORDS[i+1]}" = = ]; then [ $((i + 2)) -ge "$COMP_CWORD" ] || words+=("''${COMP_WORDS[i+2]}") i=$((i + 2)) @@ -635,9 +663,9 @@ let COMPREPLY=($(compgen -W "$(git -C "$src/''${repo:-.}" for-each-ref --format='%(refname:short)' refs/heads 2>/dev/null)" -- "$cur")) return fi - # --checkout=BRANCH: REPO's branches, or all - if { [ "$cur" = = ] && [ "$prev" = --checkout ]; } || - { [ "$prev" = = ] && [ "''${COMP_WORDS[COMP_CWORD-2]}" = --checkout ]; }; then + # --checkout=BRANCH, --stack=BRANCH: REPO's branches, or all + if { [ "$cur" = = ] && { [ "$prev" = --checkout ] || [ "$prev" = --stack ]; }; } || + { [ "$prev" = = ] && case ''${COMP_WORDS[COMP_CWORD-2]} in --checkout | --stack) true ;; *) false ;; esac; }; then [ "$cur" = = ] && cur= COMPREPLY=($(compgen -W "$(_claude_inbox_branches ''${repo:-$repos})" -- "$cur")) return @@ -676,7 +704,7 @@ let # that's there already (nor what that excludes) local cmds= opts="-d --vm --no-fetch" o left= repolist= branchlist= g c case $cmd in - "") cmds="--list --show --take --push --checkout=" ;; + "") cmds="--list --show --take --push --checkout= --stack=" ;; list) opts="$opts --by-remote" ;; show) opts="$opts --diff --git=" ;; take) opts="$opts -f --force --pick" ;; |
