Skip to content

Allow configuring upstream repository for pull #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/bin/rustc_josh_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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))]
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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)
);
Expand Down
16 changes: 8 additions & 8 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -35,13 +35,13 @@ impl GitSync {
Self { context, proxy }
}

pub fn rustc_pull(&self) -> Result<PullResult, RustcPullError> {
pub fn rustc_pull(&self, upstream_repo: String) -> Result<PullResult, RustcPullError> {
// 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")?;
Expand All @@ -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(),
);
Expand Down Expand Up @@ -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}."#,
);
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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,
Expand Down
Loading