Skip to content

Commit 2d0f2ab

Browse files
committed
tidy: update files_modified to take CiInfo
1 parent 512cab0 commit 2d0f2ab

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/tools/tidy/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@ pub fn git_diff<S: AsRef<OsStr>>(base_commit: &str, extra_arg: S) -> Option<Stri
124124
Some(String::from_utf8_lossy(&output.stdout).into())
125125
}
126126

127-
/// Returns true if any modified file matches the predicate, or if unable to list modified files.
128-
pub fn files_modified(base_commit: &str, pred: impl Fn(&str) -> bool) -> bool {
127+
/// Returns true if any modified file matches the predicate, if we are in CI, or if unable to list modified files.
128+
pub fn files_modified(ci_info: &CiInfo, pred: impl Fn(&str) -> bool) -> bool {
129+
let Some(base_commit) = &ci_info.base_commit else {
130+
eprintln!("No base commit, assuming all files are modified");
131+
return true;
132+
};
129133
match crate::git_diff(&base_commit, "--name-status") {
130134
Some(output) => {
131135
let modified_files = output.lines().filter_map(|ln| {

src/tools/tidy/src/rustdoc_json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn check(src_path: &Path, ci_info: &crate::CiInfo, bad: &mut bool) {
1414
};
1515

1616
// First we check that `src/rustdoc-json-types` was modified.
17-
if crate::files_modified(base_commit, |p| p == RUSTDOC_JSON_TYPES) {
17+
if crate::files_modified(ci_info, |p| p == RUSTDOC_JSON_TYPES) {
1818
// `rustdoc-json-types` was not modified so nothing more to check here.
1919
println!("`rustdoc-json-types` was not modified.");
2020
}

0 commit comments

Comments
 (0)