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:
Oskar Kapala 2026-06-03 18:04:38 +02:00
parent f9b145585f
commit e6a2443412

View file

@ -36,22 +36,18 @@ require_clean_tree() {
[ -z "$dirty" ] || prefail "working tree is not clean — stash or commit first"
}
worktree_count() {
# count registered worktrees that are NOT the main checkout
worktree_paths() {
# list worktree paths (excluding main); || true prevents grep exit-1 when empty
local main_path
main_path=$(git rev-parse --show-toplevel)
git worktree list --porcelain \
| awk '/^worktree /{p=$2} /^$/{print p}' \
| grep -cv "^${main_path}$"
| grep -v "^${main_path}$" \
|| true
}
worktree_paths() {
# list worktree paths (excluding main)
local main_path
main_path=$(git rev-parse --show-toplevel)
git worktree list --porcelain \
| awk '/^worktree /{p=$2} /^$/{print p}' \
| grep -v "^${main_path}$"
worktree_count() {
worktree_paths | wc -l
}
branch_exists_local() { git show-ref --verify --quiet "refs/heads/$1"; }