summaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/claude-inbox.nix46
1 files changed, 40 insertions, 6 deletions
diff --git a/pkgs/claude-inbox.nix b/pkgs/claude-inbox.nix
index 05d864a..ccb0403 100644
--- a/pkgs/claude-inbox.nix
+++ b/pkgs/claude-inbox.nix
@@ -46,6 +46,11 @@ let
conflict, it stops there: resolve, git cherry-pick --continue,
then --push; or git cherry-pick --abort. Needs master checked
out.
+ --checkout=BRANCH (or --checkout BRANCH)
+ Fetch REPO first, then check out BRANCH there, detached (no
+ local branch). Only with a clean working tree: nothing
+ changed, nothing untracked, no merge, rebase, cherry-pick or
+ revert going on.
--push [REPO] [-f|--force]
Push master to claude's master (and make that master's
upstream, if it has none).
@@ -114,7 +119,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)|COMMAND)($x|$)/\1$C_CMD\2$C_OFF\4/; ta" \
+ -e ":a; s/(^|$x)(--(list|show|take|push|checkout)|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"
@@ -157,9 +162,11 @@ let
--vm) vm=$2; shift ;;
--no-fetch) fetch= ;;
--by-remote) by=remote ;;
- --list | --show | --take | --push)
- test -z "$cmd" || test "$cmd" = "''${1#--}" || die "--$cmd or $1, not both"
- cmd=''${1#--} ;;
+ --list | --show | --take | --push | --checkout | --checkout=*)
+ c=''${1%%=*} c=''${c#--}
+ test -z "$cmd" || test "$cmd" = "$c" || die "--$cmd or --$c, not both"
+ case $1 in --checkout=*) words+=("''${1#--checkout=}") ;; esac
+ cmd=$c ;;
-f | --force) force=1 ;;
--pick) pick=1 ;;
--diff) diff=1 what= ;;
@@ -263,7 +270,7 @@ let
prefetch=
if test -n "$fetch"; then
case $cmd in
- show) prefetch=1 ;;
+ show | checkout) prefetch=1 ;;
"") if test ''${#words[@]} = 2 || ! is_repo "''${words[0]}"; then prefetch=1; fi ;;
esac
fi
@@ -293,6 +300,7 @@ let
test -n "$b" || test -z "$diff" || die "--show --diff needs a BRANCH" ;;
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" ;;
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
@@ -475,6 +483,18 @@ let
fi
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
+ git -C "$r" switch -q --detach "claude/$b"
+ echo "claude-inbox: $name: at $b, 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
@@ -506,6 +526,13 @@ 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
+ if [ "''${COMP_WORDS[i+1]}" = = ]; then
+ [ $((i + 2)) -ge "$COMP_CWORD" ] || words+=("''${COMP_WORDS[i+2]}")
+ i=$((i + 2))
+ fi ;;
--diff | --git) [ "''${COMP_WORDS[i+1]}" != = ] || i=$((i + 2)) ;;
-*) ;;
*) words+=("$w") ;;
@@ -575,6 +602,13 @@ 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
+ [ "$cur" = = ] && cur=
+ COMPREPLY=($(compgen -W "$(_claude_inbox_branches ''${repo:-$repos})" -- "$cur"))
+ return
+ fi
# --git=ARGS: git log's options, or with --diff, git diff's
if { [ "$cur" = = ] && [ "$prev" = --git ]; } ||
{ [ "$prev" = = ] && [ "''${COMP_WORDS[COMP_CWORD-2]}" = --git ]; }; then
@@ -609,7 +643,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" ;;
+ "") cmds="--list --show --take --push --checkout=" ;;
list) opts="$opts --by-remote" ;;
show) opts="$opts --diff --git=" ;;
take) opts="$opts -f --force --pick" ;;