isStrictlyUnderDir function

bool isStrictlyUnderDir(
  1. String dir,
  2. String path
)

Whether path is strictly contained within dir — the scope gate that guarantees the reaper can only ever delete inside the_grid's own worktrees root. gc's isStrictlyUnderDir (cmd/gc/bead_worktree_reaper.go:191-198).

Both sides are symlink-canonicalized first (gc's canonicalWorktreePath, git.go:362-367): git worktree list reports resolved paths (e.g. macOS /private/var for a /var tmp dir), so a raw prefix check against an unresolved root would spuriously reject a legitimate child.

Implementation

bool isStrictlyUnderDir(String dir, String path) {
  final rel = p.relative(_canonical(path), from: _canonical(dir));
  return rel != '.' && !rel.startsWith('..');
}