Skip to content

Commit 776187d

Browse files
authored
Rollup merge of rust-lang#129584 - lolbinarycat:old-upstream-warning, r=albertlarsan68
warn the user if the upstream master branch is old fixes rust-lang#129528
2 parents 7d01557 + 3743cdb commit 776187d

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/bootstrap/src/core/build_steps/format.rs

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ fn get_modified_rs_files(build: &Builder<'_>) -> Result<Option<Vec<String>>, Str
9393
if !verify_rustfmt_version(build) {
9494
return Ok(None);
9595
}
96-
9796
get_git_modified_files(&build.config.git_config(), Some(&build.config.src), &["rs"])
9897
}
9998

src/bootstrap/src/core/sanity.rs

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use std::ffi::{OsStr, OsString};
1313
use std::path::PathBuf;
1414
use std::{env, fs};
1515

16+
use build_helper::git::warn_old_master_branch;
17+
1618
#[cfg(not(feature = "bootstrap-self-test"))]
1719
use crate::builder::Builder;
1820
use crate::builder::Kind;
@@ -375,4 +377,14 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
375377
if let Some(ref s) = build.config.ccache {
376378
cmd_finder.must_have(s);
377379
}
380+
381+
// this warning is useless in CI,
382+
// and CI probably won't have the right branches anyway.
383+
if !build_helper::ci::CiEnv::is_ci() {
384+
if let Err(e) = warn_old_master_branch(&build.config.git_config(), &build.config.src)
385+
.map_err(|e| e.to_string())
386+
{
387+
eprintln!("unable to check if upstream branch is old: {e}");
388+
}
389+
}
378390
}

src/tools/build_helper/src/git.rs

+34
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,37 @@ pub fn get_git_untracked_files(
159159
.collect();
160160
Ok(Some(files))
161161
}
162+
163+
/// Print a warning if the branch returned from `updated_master_branch` is old
164+
///
165+
/// For certain configurations of git repository, this remote will not be
166+
/// updated when running `git pull`.
167+
///
168+
/// This can result in formatting thousands of files instead of a dozen,
169+
/// so we should warn the user something is wrong.
170+
pub fn warn_old_master_branch(
171+
config: &GitConfig<'_>,
172+
git_dir: &Path,
173+
) -> Result<(), Box<dyn std::error::Error>> {
174+
use std::time::Duration;
175+
const WARN_AFTER: Duration = Duration::from_secs(60 * 60 * 24 * 10);
176+
let updated_master = updated_master_branch(config, Some(git_dir))?;
177+
let branch_path = git_dir.join(".git/refs/remotes").join(&updated_master);
178+
match std::fs::metadata(branch_path) {
179+
Ok(meta) => {
180+
if meta.modified()?.elapsed()? > WARN_AFTER {
181+
eprintln!("warning: {updated_master} has not been updated in 10 days");
182+
} else {
183+
return Ok(());
184+
}
185+
}
186+
Err(err) => {
187+
eprintln!("warning: unable to check if {updated_master} is old due to error: {err}")
188+
}
189+
}
190+
eprintln!(
191+
"warning: {updated_master} is used to determine if files have been modified\n\
192+
warning: if it is not updated, this may cause files to be needlessly reformatted"
193+
);
194+
Ok(())
195+
}

0 commit comments

Comments
 (0)