From f26071533484af489f11b61455c2ab216f975f2f Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sat, 14 Mar 2026 18:22:19 +0100 Subject: [PATCH] update --- src/lib.rs | 7 ++++--- tests/integration_tests.rs | 16 +++++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0f2e7f8..08ca864 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,14 +103,15 @@ fn append_date_and_git_hash(output_path: &mut Option, config: &Config) } if config.append_git_hash { - for dir in &config.directory { - match Repository::open(dir) { + 'outer: for dir in &config.directory { + match Repository::discover(dir) { Ok(repo) => { let head = repo.head().context("Failed to get repository HEAD")?; if let Some(oid) = head.target() { new_filename.push('_'); new_filename.push_str(&oid.to_string()[..7]); info!("Appending git hash to filename."); + break 'outer; } } Err(_) => warn!("Not a git repository, cannot append git hash."), @@ -306,7 +307,7 @@ fn write_content_lines(writer: &mut dyn Write, content: &str, line_numbers: bool writeln!(writer, "{:4} | {}", i + 1, line)?; } } else { - writeln!(writer, "{}", content)?; + write!(writer, "{}", content)?; } Ok(()) } diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index fc90fb8..3135678 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1,4 +1,4 @@ -use codebase_to_prompt::{Config, Format, run}; +use codebase_to_prompt::{run, Config, Format}; use std::fs; use std::path::PathBuf; @@ -18,7 +18,7 @@ fn test_run_with_markdown_format() { line_numbers: false, ignore_hidden: true, respect_gitignore: true, - relative_path: false, + relative_path: true, }; let result = run(config); @@ -76,7 +76,13 @@ fn test_run_with_git_hash_append() { let result = run(config); assert!(result.is_ok()); - let output_file_name = output_file.file_name().unwrap().to_str().unwrap(); - assert!(output_file_name.contains("output")); - assert!(output_file_name.len() > "output".len()); + let hashed_file = fs::read_dir(temp_dir.path()) + .unwrap() + .filter_map(|e| e.ok()) + .find(|e| { + let name = e.file_name(); + let name = name.to_string_lossy(); + name.starts_with("output_") && name.ends_with(".txt") + }); + assert!(hashed_file.is_some(), "expected output file with git hash suffix"); }