fix #106261, formater should not try to format non-Rust files
This commit is contained in:
@@ -74,11 +74,11 @@ fn update_rustfmt_version(build: &Builder<'_>) {
|
|||||||
t!(std::fs::write(stamp_file, version))
|
t!(std::fs::write(stamp_file, version))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the files modified between the `merge-base` of HEAD and
|
/// Returns the Rust files modified between the `merge-base` of HEAD and
|
||||||
/// rust-lang/master and what is now on the disk.
|
/// rust-lang/master and what is now on the disk.
|
||||||
///
|
///
|
||||||
/// Returns `None` if all files should be formatted.
|
/// Returns `None` if all files should be formatted.
|
||||||
fn get_modified_files(build: &Builder<'_>) -> Option<Vec<String>> {
|
fn get_modified_rs_files(build: &Builder<'_>) -> Option<Vec<String>> {
|
||||||
let Ok(remote) = get_rust_lang_rust_remote() else {return None;};
|
let Ok(remote) = get_rust_lang_rust_remote() else {return None;};
|
||||||
if !verify_rustfmt_version(build) {
|
if !verify_rustfmt_version(build) {
|
||||||
return None;
|
return None;
|
||||||
@@ -95,6 +95,7 @@ fn get_modified_files(build: &Builder<'_>) -> Option<Vec<String>> {
|
|||||||
)
|
)
|
||||||
.lines()
|
.lines()
|
||||||
.map(|s| s.trim().to_owned())
|
.map(|s| s.trim().to_owned())
|
||||||
|
.filter(|f| Path::new(f).extension().map_or(false, |ext| ext == "rs"))
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -195,7 +196,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
|
|||||||
ignore_fmt.add(&format!("!/{}", untracked_path)).expect(&untracked_path);
|
ignore_fmt.add(&format!("!/{}", untracked_path)).expect(&untracked_path);
|
||||||
}
|
}
|
||||||
if !check && paths.is_empty() {
|
if !check && paths.is_empty() {
|
||||||
if let Some(files) = get_modified_files(build) {
|
if let Some(files) = get_modified_rs_files(build) {
|
||||||
for file in files {
|
for file in files {
|
||||||
println!("formatting modified file {file}");
|
println!("formatting modified file {file}");
|
||||||
ignore_fmt.add(&format!("/{file}")).expect(&file);
|
ignore_fmt.add(&format!("/{file}")).expect(&file);
|
||||||
|
|||||||
Reference in New Issue
Block a user