fix(dev): agent.sh worktree_count/paths grep exit-1 on empty set
grep -cv (and grep -v) return exit code 1 when there are zero matches. With set -euo pipefail this silently aborted the script before count was returned — causing 'agent.sh new' to fail on a fresh repo with no existing worktrees. Fix: move the grep -v into worktree_paths with '|| true' so the function always exits 0, then derive worktree_count via wc -l.
This commit is contained in:
parent
f9b145585f
commit
e6a2443412
|
|
@ -36,22 +36,18 @@ require_clean_tree() {
|
||||||
[ -z "$dirty" ] || prefail "working tree is not clean — stash or commit first"
|
[ -z "$dirty" ] || prefail "working tree is not clean — stash or commit first"
|
||||||
}
|
}
|
||||||
|
|
||||||
worktree_count() {
|
worktree_paths() {
|
||||||
# count registered worktrees that are NOT the main checkout
|
# list worktree paths (excluding main); || true prevents grep exit-1 when empty
|
||||||
local main_path
|
local main_path
|
||||||
main_path=$(git rev-parse --show-toplevel)
|
main_path=$(git rev-parse --show-toplevel)
|
||||||
git worktree list --porcelain \
|
git worktree list --porcelain \
|
||||||
| awk '/^worktree /{p=$2} /^$/{print p}' \
|
| awk '/^worktree /{p=$2} /^$/{print p}' \
|
||||||
| grep -cv "^${main_path}$"
|
| grep -v "^${main_path}$" \
|
||||||
|
|| true
|
||||||
}
|
}
|
||||||
|
|
||||||
worktree_paths() {
|
worktree_count() {
|
||||||
# list worktree paths (excluding main)
|
worktree_paths | wc -l
|
||||||
local main_path
|
|
||||||
main_path=$(git rev-parse --show-toplevel)
|
|
||||||
git worktree list --porcelain \
|
|
||||||
| awk '/^worktree /{p=$2} /^$/{print p}' \
|
|
||||||
| grep -v "^${main_path}$"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
branch_exists_local() { git show-ref --verify --quiet "refs/heads/$1"; }
|
branch_exists_local() { git show-ref --verify --quiet "refs/heads/$1"; }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue