aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-06-22 22:15:14 +0100
committerdiogo464 <[email protected]>2025-06-22 22:15:14 +0100
commitea62efa29f99791030c6e486955580051ced3e29 (patch)
tree73ee85d06eefd7ee3fc4998f81a69abcdc3e3e5e /src
parent2b4bca30e88f99b803911dbbc9764d7e9a447d31 (diff)
Change default root directory to use .demon subdirectory
- Modified find_git_root() to create and return <git_root>/.demon instead of <git_root> - Auto-creates .demon directory if it doesn't exist - Added proper error handling for edge cases (file vs directory conflicts, permissions) - Maintains backward compatibility with explicit --root-dir flag - Added comprehensive test to verify new default behavior - Fixed test argument ordering for test_list_empty Files are now organized as: - Before: /project/daemon.pid, /project/daemon.stdout, /project/daemon.stderr - After: /project/.demon/daemon.pid, /project/.demon/daemon.stdout, /project/.demon/daemon.stderr 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/main.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 6fbab07..dd7793f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -327,10 +327,11 @@ fn run_command(command: Commands) -> Result<()> {
327fn find_git_root() -> Result<PathBuf> { 327fn find_git_root() -> Result<PathBuf> {
328 let mut current = std::env::current_dir()?; 328 let mut current = std::env::current_dir()?;
329 329
330 loop { 330 // Find the git root directory
331 let git_root = loop {
331 let git_path = current.join(".git"); 332 let git_path = current.join(".git");
332 if git_path.exists() { 333 if git_path.exists() {
333 return Ok(current); 334 break current;
334 } 335 }
335 336
336 match current.parent() { 337 match current.parent() {
@@ -339,7 +340,30 @@ fn find_git_root() -> Result<PathBuf> {
339 "No git repository found. Please specify --root-dir or run from within a git repository" 340 "No git repository found. Please specify --root-dir or run from within a git repository"
340 )), 341 )),
341 } 342 }
343 };
344
345 // Create .demon subdirectory within git root
346 let demon_dir = git_root.join(".demon");
347
348 // Handle the case where .demon already exists
349 if demon_dir.exists() {
350 if !demon_dir.is_dir() {
351 return Err(anyhow::anyhow!(
352 "Path {} exists but is not a directory. Please remove it or specify --root-dir",
353 demon_dir.display()
354 ));
355 }
356 // .demon exists and is a directory, we can use it
357 return Ok(demon_dir);
342 } 358 }
359
360 // Create .demon directory
361 std::fs::create_dir(&demon_dir)
362 .with_context(|| format!("Failed to create daemon directory {}", demon_dir.display()))?;
363
364 tracing::info!("Created daemon directory: {}", demon_dir.display());
365
366 Ok(demon_dir)
343} 367}
344 368
345fn resolve_root_dir(global: &Global) -> Result<PathBuf> { 369fn resolve_root_dir(global: &Global) -> Result<PathBuf> {