Skip to content

Commit cd8a015

Browse files
committed
presence of .codeowners-skip-untracked-files skips untracked files
1 parent 94c9bdf commit cd8a015

File tree

9 files changed

+17
-18
lines changed

9 files changed

+17
-18
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "codeowners"
3-
version = "0.2.11"
3+
version = "0.2.12"
44
edition = "2024"
55

66
[profile.release]

src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ pub struct Config {
2525
#[serde(default = "default_ignore_dirs")]
2626
pub ignore_dirs: Vec<String>,
2727

28-
#[serde(default = "default_skip_untracked_files")]
29-
pub skip_untracked_files: bool,
28+
#[serde(default = "default_skip_untracked_files_config_path")]
29+
pub skip_untracked_files_config_path: String,
3030
}
3131

3232
#[allow(dead_code)]
@@ -63,8 +63,8 @@ fn vendored_gems_path() -> String {
6363
"vendored/".to_string()
6464
}
6565

66-
fn default_skip_untracked_files() -> bool {
67-
true
66+
fn default_skip_untracked_files_config_path() -> String {
67+
".codeowners-skip-untracked-files".to_string()
6868
}
6969

7070
fn default_ignore_dirs() -> Vec<String> {

src/ownership/for_file_fast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ mod tests {
303303
vendored_gems_path: vendored_path.to_string(),
304304
cache_directory: "tmp/cache/codeowners".to_string(),
305305
ignore_dirs: vec![],
306-
skip_untracked_files: false,
306+
skip_untracked_files_config_path: ".codeowners-skip-untracked-files".to_string(),
307307
}
308308
}
309309

src/project_builder.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'a> ProjectBuilder<'a> {
6161
// Prune traversal early: skip heavy and irrelevant directories
6262
let ignore_dirs = self.config.ignore_dirs.clone();
6363
let base_path = self.base_path.clone();
64-
let untracked_files = if self.config.skip_untracked_files {
64+
let untracked_files = if skip_untracked_files_config_path_exists(&self.base_path, &self.config.skip_untracked_files_config_path) {
6565
files::untracked_files(&base_path).unwrap_or_default()
6666
} else {
6767
vec![]
@@ -297,6 +297,12 @@ fn matches_globs(path: &Path, globs: &[String]) -> bool {
297297
}
298298
}
299299

300+
// If skip_untracked_files_config_path exists, we skip untracked files. We don't do this be default because it's slow.
301+
fn skip_untracked_files_config_path_exists(base_path: &Path, skip_untracked_files_config_path: &str) -> bool {
302+
let path = base_path.join(skip_untracked_files_config_path);
303+
path.exists()
304+
}
305+
300306
fn ruby_package_owner(path: &Path) -> Result<Option<String>, Error> {
301307
let file = File::open(path).change_context(Error::Io)?;
302308
let deserializer: deserializers::RubyPackage = serde_yaml::from_reader(file).change_context(Error::SerdeYaml)?;

tests/fixtures/invalid_project/config/code_ownership.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ team_file_glob:
88
- config/teams/**/*.yml
99
vendored_gems_path: gems
1010
unowned_globs:
11-
skip_untracked_files: false

tests/fixtures/multiple-directory-owners/config/code_ownership.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ javascript_package_paths:
77
- javascript/packages/**
88
vendored_gems_path: gems
99
team_file_glob:
10-
- config/teams/**/*.yml
11-
skip_untracked_files: false
10+
- config/teams/**/*.yml

tests/fixtures/valid_project/config/code_ownership.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ team_file_glob:
88
- config/teams/**/*.yml
99
unbuilt_gems_path: gems
1010
unowned_globs:
11-
skip_untracked_files: false

tests/untracked_files_test.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ fn test_skip_untracked_files() -> Result<(), Box<dyn Error>> {
2121
.assert()
2222
.failure();
2323

24-
// Add skip_untracked_false: false to project_root/config/code_ownership.yml
25-
let config_path = project_root.join("config/code_ownership.yml");
26-
let original = fs::read_to_string(&config_path)?;
27-
// Change payroll.rb ownership from @PayrollTeam to @PaymentsTeam to induce a mismatch
28-
let modified = original.replace("skip_untracked_files: false", "skip_untracked_files: true");
29-
fs::write(&config_path, modified)?;
24+
let skip_untracked_files_config_path = project_root.join(".codeowners-skip-untracked-files");
25+
fs::write(&skip_untracked_files_config_path, "true")?;
3026

3127
// should succeed if skip_untracked_false is false
3228
Command::cargo_bin("codeowners")?

0 commit comments

Comments
 (0)