Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "codeowners"
version = "0.2.11"
version = "0.2.13"
edition = "2024"

[profile.release]
Expand Down Expand Up @@ -34,6 +34,6 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
[dev-dependencies]
assert_cmd = "2.0.16"
rusty-hook = "^0.11.2"
predicates = "3.1.2"
predicates = "3.1.3"
pretty_assertions = "1.4.1" # Shows a more readable diff when comparing objects
indoc = "2.0.5"
7 changes: 0 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ pub struct Config {

#[serde(default = "default_ignore_dirs")]
pub ignore_dirs: Vec<String>,

#[serde(default = "default_skip_untracked_files")]
pub skip_untracked_files: bool,
}

#[allow(dead_code)]
Expand Down Expand Up @@ -63,10 +60,6 @@ fn vendored_gems_path() -> String {
"vendored/".to_string()
}

fn default_skip_untracked_files() -> bool {
true
}

fn default_ignore_dirs() -> Vec<String> {
vec![
".cursor".to_owned(),
Expand Down
157 changes: 0 additions & 157 deletions src/files.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ pub mod cache;
pub(crate) mod common_test;
pub mod config;
pub mod crosscheck;
pub(crate) mod files;
pub mod ownership;
pub(crate) mod project;
pub mod project_builder;
pub mod project_file_builder;
pub mod runner;
pub(crate) mod tracked_files;
1 change: 0 additions & 1 deletion src/ownership/for_file_fast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ mod tests {
vendored_gems_path: vendored_path.to_string(),
cache_directory: "tmp/cache/codeowners".to_string(),
ignore_dirs: vec![],
skip_untracked_files: false,
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/project_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use tracing::{instrument, warn};
use crate::{
cache::Cache,
config::Config,
files,
project::{DirectoryCodeownersFile, Error, Package, PackageType, Project, ProjectFile, Team, VendoredGem, deserializers},
project_file_builder::ProjectFileBuilder,
tracked_files,
};

type AbsolutePath = PathBuf;
Expand Down Expand Up @@ -61,16 +61,16 @@ impl<'a> ProjectBuilder<'a> {
// Prune traversal early: skip heavy and irrelevant directories
let ignore_dirs = self.config.ignore_dirs.clone();
let base_path = self.base_path.clone();
let untracked_files = if self.config.skip_untracked_files {
files::untracked_files(&base_path).unwrap_or_default()
} else {
vec![]
};
let tracked_files = tracked_files::find_tracked_files(&self.base_path);

builder.filter_entry(move |entry: &DirEntry| {
let path = entry.path();
let file_name = entry.file_name().to_str().unwrap_or("");
if !untracked_files.is_empty() && untracked_files.contains(&path.to_path_buf()) {
if let Some(tracked_files) = &tracked_files
&& let Some(ft) = entry.file_type()
&& ft.is_file()
&& !tracked_files.contains_key(path)
{
return false;
}
if let Some(ft) = entry.file_type()
Expand Down
58 changes: 58 additions & 0 deletions src/tracked_files.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use std::{
collections::HashMap,
path::{Path, PathBuf},
process::Command,
};

pub(crate) fn find_tracked_files(base_path: &Path) -> Option<HashMap<PathBuf, bool>> {
let output = Command::new("git")
.args(["ls-files", "--full-name", "-z", "--", "."])
.current_dir(base_path)
.output()
.ok()?;

if !output.status.success() {
return None;
}

let results: HashMap<PathBuf, bool> = output
.stdout
.split(|&b| b == b'\0')
.filter(|chunk| !chunk.is_empty())
.map(|rel| std::str::from_utf8(rel).ok().map(|s| (base_path.join(s), true)))
.collect::<Option<HashMap<PathBuf, bool>>>()?;

Some(results)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_untracked_files() {
let tmp_dir = tempfile::tempdir().unwrap();
assert!(find_tracked_files(tmp_dir.path()).is_none());

std::process::Command::new("git")
.arg("init")
.current_dir(tmp_dir.path())
.output()
.expect("failed to run git init");

std::fs::write(tmp_dir.path().join("test.txt"), "test").unwrap();
let tracked = find_tracked_files(tmp_dir.path()).unwrap();
assert!(tracked.is_empty());

std::process::Command::new("git")
.arg("add")
.arg("test.txt")
.current_dir(tmp_dir.path())
.output()
.expect("failed to add test.txt");

let tracked = find_tracked_files(tmp_dir.path()).unwrap();
assert!(tracked.len() == 1);
assert!(tracked.get(&tmp_dir.path().join("test.txt")).unwrap());
}
}
Loading