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
7 changes: 6 additions & 1 deletion crates/prek/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,13 @@ impl Store {
config_paths: impl Iterator<Item = &'a Path>,
) -> Result<(), Error> {
let mut tracked = self.tracked_configs()?;
let mut changed = false;
for config_path in config_paths {
tracked.insert(config_path.to_path_buf());
changed |= tracked.insert(config_path.to_path_buf());
}

if !changed {
return Ok(());
}

let tracking_file = self.config_tracking_file();
Expand Down
44 changes: 44 additions & 0 deletions crates/prek/tests/run.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::path::Path;
use std::time::SystemTime;

use anyhow::Result;
use assert_cmd::assert::OutputAssertExt;
Expand Down Expand Up @@ -75,6 +76,49 @@ fn run_basic() -> Result<()> {
Ok(())
}

#[test]
fn run_does_not_rewrite_unchanged_config_tracking_file() -> Result<()> {
let context = TestContext::new();
context.init_project();

context.write_pre_commit_config(indoc::indoc! {r#"
repos:
- repo: local
hooks:
- id: noop
name: Noop
language: system
entry: "true"
always_run: true
"#});
context.git_add(".");

context.run().arg("--all-files").assert().success();

let tracking_file = context.home_dir().child("config-tracking.json");
tracking_file.assert(predicate::path::is_file());
let original_content = fs_err::read_to_string(tracking_file.path())?;

fs_err::OpenOptions::new()
.write(true)
.open(tracking_file.path())?
.set_modified(SystemTime::UNIX_EPOCH)?;
let original_modified = fs_err::metadata(tracking_file.path())?.modified()?;

context.run().arg("--all-files").assert().success();

assert_eq!(
fs_err::read_to_string(tracking_file.path())?,
original_content
);
assert_eq!(
fs_err::metadata(tracking_file.path())?.modified()?,
original_modified
);

Ok(())
}

#[test]
fn run_glob_patterns_with_multiple_hooks() -> Result<()> {
let context = TestContext::new();
Expand Down
Loading