From e6a2443412088b327418794faa8ca2a32501be6a Mon Sep 17 00:00:00 2001 From: Oskar Kapala Date: Wed, 3 Jun 2026 18:04:38 +0200 Subject: [PATCH] fix(dev): agent.sh worktree_count/paths grep exit-1 on empty set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- scripts/dev/agent.sh | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/scripts/dev/agent.sh b/scripts/dev/agent.sh index ae79daf..4501974 100755 --- a/scripts/dev/agent.sh +++ b/scripts/dev/agent.sh @@ -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"; }