Skip to content

Commit f3dc740

Browse files
committed
exclude upstream check from 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` as we specifically treat bors commits as merge commits, which also exist on upstream. Therefore, checking the upstream branch unnecessarily complicates things and also causes incorrect results. Signed-off-by: onur-ozkan <[email protected]>
1 parent 11ee3a8 commit f3dc740

File tree

1 file changed

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

1 file changed

+3
-21
lines changed

src/tools/build_helper/src/git.rs

+3-21
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,10 @@ pub fn updated_master_branch(
9696
Err("Cannot find any suitable upstream master branch".to_owned())
9797
}
9898

99-
/// Finds the nearest merge commit by comparing the local `HEAD` with the upstream branch's state.
100-
/// To work correctly, the upstream remote must be properly configured using `git remote add <name> <url>`.
101-
/// In most cases `get_closest_merge_commit` is the function you are looking for as it doesn't require remote
102-
/// to be configured.
103-
fn git_upstream_merge_base(
104-
config: &GitConfig<'_>,
105-
git_dir: Option<&Path>,
106-
) -> Result<String, String> {
107-
let updated_master = updated_master_branch(config, git_dir)?;
108-
let mut git = Command::new("git");
109-
if let Some(git_dir) = git_dir {
110-
git.current_dir(git_dir);
111-
}
112-
Ok(output_result(git.arg("merge-base").arg(&updated_master).arg("HEAD"))?.trim().to_owned())
113-
}
114-
11599
/// Searches for the nearest merge commit in the repository that also exists upstream.
116100
///
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.
101+
/// It looks for the most recent commit made by the merge bot by matching the author's email
102+
/// address with the merge bot's email.
119103
pub fn get_closest_merge_commit(
120104
git_dir: Option<&Path>,
121105
config: &GitConfig<'_>,
@@ -127,14 +111,12 @@ pub fn get_closest_merge_commit(
127111
git.current_dir(git_dir);
128112
}
129113

130-
let merge_base = git_upstream_merge_base(config, git_dir).unwrap_or_else(|_| "HEAD".into());
131-
132114
git.args([
133115
"rev-list",
134116
&format!("--author={}", config.git_merge_commit_email),
135117
"-n1",
136118
"--first-parent",
137-
&merge_base,
119+
"HEAD",
138120
]);
139121

140122
if !target_paths.is_empty() {

0 commit comments

Comments
 (0)