Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Sanitize operation name to avoid creating subdirectories
Maximilian Roosea51ebc5c5fd
diff --git a/src/commands/process.rs b/src/commands/process.rsindex d52e40392..6c4a76ee0 100644--- a/src/commands/process.rs+++ b/src/commands/process.rs@@ -37,9 +37,10 @@ pub fn spawn_detached(// Generate log filename (no timestamp - overwrites on each run)// Format: {branch}-{name}.log (e.g., "feature-post-start-npm.log", "bugfix-remove.log")- // Sanitize branch name: replace '/' with '-' to avoid creating subdirectories+ // Sanitize branch and name: replace '/' with '-' to avoid creating subdirectorieslet safe_branch = branch.replace('/', "-");- let log_path = log_dir.join(format!("{}-{}.log", safe_branch, name));+ let safe_name = name.replace('/', "-");+ let log_path = log_dir.join(format!("{}-{}.log", safe_branch, safe_name));// Create log filelet log_file = fs::File::create(&log_path)diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rsindex 8a0a0517a..39101d5ce 100644--- a/src/git/repository/mod.rs+++ b/src/git/repository/mod.rs@@ -401,15 +401,37 @@ impl Repository {}/// Get the git common directory (the actual .git directory for the repository).+ ///+ /// Always returns an absolute path, resolving any relative paths returned by git.pub fn git_common_dir(&self) -> Result<PathBuf, GitError> {let stdout = self.run_command(&["rev-parse", "--git-common-dir"])?;- Ok(PathBuf::from(stdout.trim()))+ let path = PathBuf::from(stdout.trim());++ // Resolve relative paths against the repo's directory+ if path.is_relative() {+ self.path.join(&path).canonicalize().map_err(|e| {+ GitError::CommandFailed(format!("Failed to resolve git common directory\n {e}"))+ })+ } else {+ Ok(path)+ }}/// Get the git directory (may be different from common-dir in worktrees).+ ///+ /// Always returns an absolute path, resolving any relative paths returned by git.pub fn git_dir(&self) -> Result<PathBuf, GitError> {let stdout = self.run_command(&["rev-parse", "--git-dir"])?;- Ok(PathBuf::from(stdout.trim()))+ let path = PathBuf::from(stdout.trim());++ // Resolve relative paths against the repo's directory+ if path.is_relative() {+ self.path.join(&path).canonicalize().map_err(|e| {+ GitError::CommandFailed(format!("Failed to resolve git directory\n {e}"))+ })+ } else {+ Ok(path)+ }}/// Get the base directory where worktrees are created relative to.