Skip to content

Commit e936a64

Browse files
committed
force HEAD for non-CI env in in build_helper::git::get_closest_merge_commit
When rust-lang/rust is configured as remote, some of the git logic (for tracking changed files) that uses get_closest_merge_commit starts to produce annoying results as the upstream branch becomes outdated quickly (since it isn't updated with git pull). We can rely on HEAD for non-CI environments as we specifically treat bors commits as merge commits, which also exist on upstream. Signed-off-by: onur-ozkan <[email protected]>
1 parent 11ee3a8 commit e936a64

File tree

1 file changed

+15
-3
lines changed
  • src/tools/build_helper/src

1 file changed

+15
-3
lines changed

src/tools/build_helper/src/git.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::path::{Path, PathBuf};
22
use std::process::{Command, Stdio};
33

4+
use crate::ci::CiEnv;
5+
46
pub struct GitConfig<'a> {
57
pub git_repository: &'a str,
68
pub nightly_branch: &'a str,
@@ -114,8 +116,8 @@ fn git_upstream_merge_base(
114116

115117
/// Searches for the nearest merge commit in the repository that also exists upstream.
116118
///
117-
/// If it fails to find the upstream remote, it then looks for the most recent commit made
118-
/// by the merge bot by matching the author's email address with the merge bot's email.
119+
/// It looks for the most recent commit made by the merge bot by matching the author's email
120+
/// address with the merge bot's email.
119121
pub fn get_closest_merge_commit(
120122
git_dir: Option<&Path>,
121123
config: &GitConfig<'_>,
@@ -127,7 +129,17 @@ pub fn get_closest_merge_commit(
127129
git.current_dir(git_dir);
128130
}
129131

130-
let merge_base = git_upstream_merge_base(config, git_dir).unwrap_or_else(|_| "HEAD".into());
132+
let merge_base = {
133+
let res = git_upstream_merge_base(config, git_dir);
134+
135+
if CiEnv::is_ci() {
136+
res.unwrap()
137+
} else {
138+
// For non-CI environments, ignore rust-lang/rust upstream as it usually gets
139+
// outdated very quickly.
140+
"HEAD".to_string()
141+
}
142+
};
131143

132144
git.args([
133145
"rev-list",

0 commit comments

Comments
 (0)