surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | import Git from '../git' |
| 2 | import { normalPathOf } from './normal-path-of.js' |
| 3 | |
| 4 | /** |
| 5 | * Whether a file a tool edited lies outside the pinned working tree, by |
| 6 | * how the paths are spelled alone (normalPathOf): no row could show it. |
| 7 | * |
| 8 | * A relative path is read from the session's directory. Where that |
| 9 | * directory is itself not spelled under the top (a symbolic link on the |
| 10 | * way to it), spelling proves nothing and nothing is outside. |
| 11 | * |
| 12 | * @param path the path the tool was called with |
| 13 | * @param tree the session's directory and the working tree's top |
| 14 | * @returns true only for a path surely outside the tree |
| 15 | */ |
| 16 | export function isOutsideWorkingTree( |
| 17 | path: string, |
| 18 | tree: { cwd: string; toplevel: string }, |
| 19 | ): boolean { |
| 20 | const top = normalPathOf(tree.toplevel) |
| 21 | const absolute = Git.isAbsolutePath(path) ? path : `${tree.cwd}/${path}` |
| 22 | |
| 23 | const isUnderTop = (spelled: string) => |
| 24 | top === '' || spelled === top || spelled.startsWith(`${top}/`) |
| 25 | |
| 26 | return ( |
| 27 | isUnderTop(normalPathOf(tree.cwd)) && !isUnderTop(normalPathOf(absolute)) |
| 28 | ) |
| 29 | } |