@imdeadpool/guardex 8.3.0 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -582,6 +582,7 @@ has_live_process_in_worktree() {
582
582
  remove_worktree_with_lock_guard() {
583
583
  local worktree="$1"
584
584
  local remove_reason="$2"
585
+ local branch="$3"
585
586
  local lock_file="${worktree}/.omx/state/agent-file-locks.json"
586
587
  local shared_lock="${repo_common_dir}/agent-file-locks.lock"
587
588
 
@@ -590,7 +591,7 @@ remove_worktree_with_lock_guard() {
590
591
  return 10
591
592
  fi
592
593
 
593
- python3 - "$shared_lock" "$lock_file" "$repo_root" "$worktree" "$remove_reason" "$DRY_RUN" <<'PY'
594
+ python3 - "$shared_lock" "$lock_file" "$repo_root" "$worktree" "$remove_reason" "$branch" "$DRY_RUN" <<'PY'
594
595
  import json
595
596
  import subprocess
596
597
  import sys
@@ -601,7 +602,7 @@ except ImportError:
601
602
  print('[agent-worktree-prune] OS file locking is unavailable; prune blocked', file=sys.stderr)
602
603
  raise SystemExit(10)
603
604
 
604
- shared_lock, lock_file, repo_root, worktree, remove_reason, dry_run = sys.argv[1:]
605
+ shared_lock, lock_file, repo_root, worktree, remove_reason, branch, dry_run = sys.argv[1:]
605
606
  try:
606
607
  with open(shared_lock, 'a+', encoding='utf-8') as lock_handle:
607
608
  fcntl.flock(lock_handle.fileno(), fcntl.LOCK_EX)
@@ -633,7 +634,16 @@ try:
633
634
  file=sys.stderr,
634
635
  )
635
636
  raise SystemExit(10)
636
- raise SystemExit(10)
637
+ if not branch.startswith(('agent/', 'work/')) or entry.get('branch') != branch:
638
+ raise SystemExit(10)
639
+
640
+ if locks:
641
+ label = 'lock' if len(locks) == 1 else 'locks'
642
+ print(
643
+ f'[agent-worktree-prune] Releasing {len(locks)} self-owned {label} '
644
+ f'while removing terminal worktree: {worktree}',
645
+ flush=True,
646
+ )
637
647
 
638
648
  print(f'[agent-worktree-prune] Removing worktree ({remove_reason}): {worktree}', flush=True)
639
649
  command = ['git', '-C', repo_root, 'worktree', 'remove', worktree, '--force']
@@ -880,7 +890,7 @@ process_entry() {
880
890
  fi
881
891
 
882
892
  local remove_status=0
883
- if remove_worktree_with_lock_guard "$wt" "$remove_reason"; then
893
+ if remove_worktree_with_lock_guard "$wt" "$remove_reason" "$branch"; then
884
894
  removed_worktrees=$((removed_worktrees + 1))
885
895
  else
886
896
  remove_status=$?