Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .agents/skills/worktrees-pnpm/scripts/refuse-main-checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ if [ -n "${CI:-}" ]; then
exit 0
fi

dirs=$(git rev-parse --path-format=absolute --git-dir --git-common-dir)
git_dir=$(printf '%s\n' "$dirs" | sed -n 1p)
common_dir=$(printf '%s\n' "$dirs" | sed -n 2p)
# Both paths are resolved physically rather than with
# `rev-parse --path-format=absolute`, which git before 2.31 rejects. Under
# `set -e` that rejection would fail the hook everywhere, worktrees included,
# leaving --no-verify as the only way to commit. `pwd -P` also settles symlinks
# and relative output, so the comparison is path to path.
git_dir=$(cd "$(git rev-parse --git-dir)" && pwd -P)
common_dir=$(cd "$(git rev-parse --git-common-dir)" && pwd -P)

if [ "$git_dir" = "$common_dir" ]; then
top=$(git rev-parse --show-toplevel)
Expand Down
7 changes: 6 additions & 1 deletion .agents/skills/worktrees-pnpm/scripts/worktree-remove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ worktree_path=$(printf '%s' "$payload" | jq -r '.worktree_path // empty')
[ -n "$worktree_path" ] || exit 0
[ -d "$worktree_path" ] || exit 0

repo_root=$(git -C "$worktree_path" rev-parse --path-format=absolute --git-common-dir 2>/dev/null | xargs dirname) || exit 0
# Resolved physically rather than with `rev-parse --path-format=absolute`, which
# git before 2.31 rejects; that failure exited 0 here and silently left every
# worktree in place. --git-common-dir can print a path relative to the worktree,
# so it is resolved from inside it.
common_dir=$(cd "$worktree_path" && cd "$(git rev-parse --git-common-dir 2>/dev/null)" && pwd -P) || exit 0
repo_root=$(dirname "$common_dir")

# Refuse to discard uncommitted changes. `git worktree remove` without --force
# already refuses, but check explicitly so the reason is greppable in debug logs.
Expand Down
Loading