MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / resolve_worktree_add_root

Function resolve_worktree_add_root

src/hooks/cursor_shell.rs:359–366  ·  view source on GitHub ↗

Resolves the filesystem root of the worktree created by a `git worktree add` command. git resolves the worktree path against `-C `/`--work-tree` overrides rather than the shell cwd, so those are honored first. The result is canonicalized when the worktree exists (it does by the time a post-shell hook fires) so symlinked components resolve the way git resolved them, falling back to lexical `..

(command: &str, cwd: &Path, worktree_path: &str)

Source from the content-addressed store, hash-verified

357/// does by the time a post-shell hook fires) so symlinked components resolve
358/// the way git resolved them, falling back to lexical `..` normalization.
359pub fn resolve_worktree_add_root(command: &str, cwd: &Path, worktree_path: &str) -> PathBuf {
360 let tokens = shell_words(command);
361 let base = git_explicit_work_dir(&tokens, cwd).unwrap_or_else(|| cwd.to_path_buf());
362 let joined = resolve_shell_path(&base, worktree_path);
363 joined
364 .canonicalize()
365 .unwrap_or_else(|_| normalize_lexically(&joined))
366}
367
368fn normalize_lexically(path: &Path) -> PathBuf {
369 let mut normalized = PathBuf::new();

Callers 2

plan_shell_hook_eventFunction · 0.85

Calls 4

shell_wordsFunction · 0.85
git_explicit_work_dirFunction · 0.85
resolve_shell_pathFunction · 0.85
normalize_lexicallyFunction · 0.85

Tested by

no test coverage detected