Remove setup-upstream-remote.sh and upstream handling.

It shouldn't be needed anymore.
This commit is contained in:
Jakub Beránek 2025-03-17 08:52:19 +01:00
parent 8515d7e257
commit 64795ecb87
4 changed files with 2 additions and 106 deletions

View file

@ -30,77 +30,6 @@ pub fn output_result(cmd: &mut Command) -> Result<String, String> {
String::from_utf8(output.stdout).map_err(|err| format!("{err:?}"))
}
/// Finds the remote for rust-lang/rust.
/// For example for these remotes it will return `upstream`.
/// ```text
/// origin https://github.com/pietroalbani/rust.git (fetch)
/// origin https://github.com/pietroalbani/rust.git (push)
/// upstream https://github.com/rust-lang/rust (fetch)
/// upstream https://github.com/rust-lang/rust (push)
/// ```
pub fn get_rust_lang_rust_remote(
config: &GitConfig<'_>,
git_dir: Option<&Path>,
) -> Result<String, String> {
let mut git = Command::new("git");
if let Some(git_dir) = git_dir {
git.current_dir(git_dir);
}
git.args(["config", "--local", "--get-regex", "remote\\..*\\.url"]);
let stdout = output_result(&mut git)?;
let rust_lang_remote = stdout
.lines()
.find(|remote| remote.contains(config.git_repository))
.ok_or_else(|| format!("{} remote not found", config.git_repository))?;
let remote_name =
rust_lang_remote.split('.').nth(1).ok_or_else(|| "remote name not found".to_owned())?;
Ok(remote_name.into())
}
pub fn rev_exists(rev: &str, git_dir: Option<&Path>) -> Result<bool, String> {
let mut git = Command::new("git");
if let Some(git_dir) = git_dir {
git.current_dir(git_dir);
}
git.args(["rev-parse", rev]);
let output = git.output().map_err(|err| format!("{err:?}"))?;
match output.status.code() {
Some(0) => Ok(true),
Some(128) => Ok(false),
None => Err(format!(
"git didn't exit properly: {}",
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
)),
Some(code) => Err(format!(
"git command exited with status code: {code}: {}",
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
)),
}
}
/// Returns the master branch from which we can take diffs to see changes.
/// This will usually be rust-lang/rust master, but sometimes this might not exist.
/// This could be because the user is updating their forked master branch using the GitHub UI
/// and therefore doesn't need an upstream master branch checked out.
/// We will then fall back to origin/master in the hope that at least this exists.
pub fn updated_master_branch(
config: &GitConfig<'_>,
git_dir: Option<&Path>,
) -> Result<String, String> {
let upstream_remote = get_rust_lang_rust_remote(config, git_dir)?;
let branch = config.nightly_branch;
for upstream_master in [format!("{upstream_remote}/{branch}"), format!("origin/{branch}")] {
if rev_exists(&upstream_master, git_dir)? {
return Ok(upstream_master);
}
}
Err("Cannot find any suitable upstream master branch".to_owned())
}
/// Represents the result of checking whether a set of paths
/// have been modified locally or not.
#[derive(PartialEq, Debug, Clone)]
@ -333,13 +262,7 @@ pub fn get_git_modified_files(
}
/// Returns the files that haven't been added to git yet.
pub fn get_git_untracked_files(
config: &GitConfig<'_>,
git_dir: Option<&Path>,
) -> Result<Option<Vec<String>>, String> {
let Ok(_updated_master) = updated_master_branch(config, git_dir) else {
return Ok(None);
};
pub fn get_git_untracked_files(git_dir: Option<&Path>) -> Result<Option<Vec<String>>, String> {
let mut git = Command::new("git");
if let Some(git_dir) = git_dir {
git.current_dir(git_dir);

View file

@ -1,24 +0,0 @@
#!/bin/bash
# In CI environments, bootstrap is forced to use the remote upstream based
# on "git_repository" and "nightly_branch" values from src/stage0 file.
# This script configures the remote as it may not exist by default.
set -euo pipefail
IFS=$'\n\t'
ci_dir=$(cd $(dirname $0) && pwd)/..
source "$ci_dir/shared.sh"
git_repository=$(parse_stage0_file_by_key "git_repository")
nightly_branch=$(parse_stage0_file_by_key "nightly_branch")
# Configure "rust-lang/rust" upstream remote only when it's not origin.
if [ -z "$(git config remote.origin.url | grep $git_repository)" ]; then
echo "Configuring https://github.com/$git_repository remote as upstream."
git remote add upstream "https://github.com/$git_repository"
REMOTE_NAME="upstream"
else
REMOTE_NAME="origin"
fi
git fetch $REMOTE_NAME $nightly_branch

View file

@ -745,7 +745,7 @@ fn modified_tests(config: &Config, dir: &Utf8Path) -> Result<Vec<Utf8PathBuf>, S
&vec!["rs", "stderr", "fixed"],
)?;
// Add new test cases to the list, it will be convenient in daily development.
let untracked_files = get_git_untracked_files(&config.git_config(), None)?.unwrap_or(vec![]);
let untracked_files = get_git_untracked_files(Some(dir))?.unwrap_or(vec![]);
let all_paths = [&files[..], &untracked_files[..]].concat();
let full_paths = {