From efe0d5ce02e18a9167cbde81794e24dca8f7e562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sun, 13 Jul 2025 13:23:56 +0200 Subject: [PATCH] Allow configuring upstream repository for `pull` --- src/bin/rustc_josh_sync.rs | 12 +++++++++--- src/sync.rs | 16 ++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/bin/rustc_josh_sync.rs b/src/bin/rustc_josh_sync.rs index ce3ec00..f0f01af 100644 --- a/src/bin/rustc_josh_sync.rs +++ b/src/bin/rustc_josh_sync.rs @@ -3,7 +3,7 @@ use clap::Parser; use rustc_josh_sync::SyncContext; use rustc_josh_sync::config::{JoshConfig, load_config}; use rustc_josh_sync::josh::{JoshProxy, try_install_josh}; -use rustc_josh_sync::sync::{GitSync, RustcPullError, UPSTREAM_REPO}; +use rustc_josh_sync::sync::{DEFAULT_UPSTREAM_REPO, GitSync, RustcPullError}; use rustc_josh_sync::utils::{get_current_head_sha, prompt}; use std::path::{Path, PathBuf}; @@ -23,6 +23,11 @@ enum Command { /// Pull changes from the main `rust-lang/rust` repository. /// This creates new commits that should be then merged into this subtree repository. Pull { + /// Override the upstream repository from which we pull changes. + /// Can be used to perform experimental pulls e.g. to test changes in the subtree repository + /// that have not yet been merged in `rust-lang/rust`. + #[clap(long, default_value(DEFAULT_UPSTREAM_REPO))] + upstream: String, #[clap(long, default_value(DEFAULT_CONFIG_PATH))] config_path: PathBuf, #[clap(long, default_value(DEFAULT_RUST_VERSION_PATH))] @@ -69,11 +74,12 @@ fn main() -> anyhow::Result<()> { Command::Pull { config_path, rust_version_path, + upstream, } => { let ctx = load_context(&config_path, &rust_version_path)?; let josh = get_josh_proxy()?; let sync = GitSync::new(ctx.clone(), josh); - match sync.rustc_pull() { + match sync.rustc_pull(upstream) { Ok(result) => { if !maybe_create_gh_pr( &ctx.config.full_repo_name(), @@ -124,7 +130,7 @@ r? @ghost"#, println!( r#"You can create the rustc PR using the following URL: -https://github.com/{UPSTREAM_REPO}/compare/{username}:{branch}?quick_pull=1&title={}&body={}"#, +https://github.com/{DEFAULT_UPSTREAM_REPO}/compare/{username}:{branch}?quick_pull=1&title={}&body={}"#, urlencoding::encode(&title), urlencoding::encode(&merge_msg) ); diff --git a/src/sync.rs b/src/sync.rs index 4da4e5b..6f6c527 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -6,7 +6,7 @@ use crate::utils::{run_command, stream_command}; use anyhow::{Context, Error}; use std::path::{Path, PathBuf}; -pub const UPSTREAM_REPO: &str = "rust-lang/rust"; +pub const DEFAULT_UPSTREAM_REPO: &str = "rust-lang/rust"; pub enum RustcPullError { /// No changes are available to be pulled. @@ -35,13 +35,13 @@ impl GitSync { Self { context, proxy } } - pub fn rustc_pull(&self) -> Result { + pub fn rustc_pull(&self, upstream_repo: String) -> Result { // The upstream commit that we want to pull let upstream_sha = { let out = run_command([ "git", "ls-remote", - &format!("https://github.com/{UPSTREAM_REPO}"), + &format!("https://github.com/{upstream_repo}"), "HEAD", ]) .context("cannot fetch upstream commit")?; @@ -59,7 +59,7 @@ impl GitSync { .start(&self.context.config) .context("cannot start josh-proxy")?; let josh_url = josh.git_url( - UPSTREAM_REPO, + &upstream_repo, Some(&upstream_sha), &self.context.config.construct_josh_filter(), ); @@ -98,7 +98,7 @@ impl GitSync { })?; let prep_message = format!( - r#"Prepare for merging from {UPSTREAM_REPO} + r#"Prepare for merging from {upstream_repo} This updates the rust-version file to {upstream_sha}."#, ); @@ -144,9 +144,9 @@ This updates the rust-version file to {upstream_sha}."#, println!("incoming ref: {incoming_ref}"); let merge_message = format!( - r#"Merge ref '{upstream_head_short}' from {UPSTREAM_REPO} + r#"Merge ref '{upstream_head_short}' from {upstream_repo} -Pull recent changes from https://github.com/{UPSTREAM_REPO} via Josh. +Pull recent changes from https://github.com/{upstream_repo} via Josh. Upstream ref: {upstream_sha} Filtered ref: {incoming_ref} @@ -241,7 +241,7 @@ This merge was created using https://github.com/rust-lang/josh-sync. &[ "git", "fetch", - &format!("https://github.com/{UPSTREAM_REPO}"), + &format!("https://github.com/{DEFAULT_UPSTREAM_REPO}"), &base_upstream_sha, ], &rustc_git,