Skip to content

Commit 0654738

Browse files
authored
Merge pull request #12 from Kobzol/pull-upstream-repo
Allow configuring upstream repository for `pull`
2 parents 88f4616 + efe0d5c commit 0654738

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/bin/rustc_josh_sync.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clap::Parser;
33
use rustc_josh_sync::SyncContext;
44
use rustc_josh_sync::config::{JoshConfig, load_config};
55
use rustc_josh_sync::josh::{JoshProxy, try_install_josh};
6-
use rustc_josh_sync::sync::{GitSync, RustcPullError, UPSTREAM_REPO};
6+
use rustc_josh_sync::sync::{DEFAULT_UPSTREAM_REPO, GitSync, RustcPullError};
77
use rustc_josh_sync::utils::{get_current_head_sha, prompt};
88
use std::path::{Path, PathBuf};
99

@@ -23,6 +23,11 @@ enum Command {
2323
/// Pull changes from the main `rust-lang/rust` repository.
2424
/// This creates new commits that should be then merged into this subtree repository.
2525
Pull {
26+
/// Override the upstream repository from which we pull changes.
27+
/// Can be used to perform experimental pulls e.g. to test changes in the subtree repository
28+
/// that have not yet been merged in `rust-lang/rust`.
29+
#[clap(long, default_value(DEFAULT_UPSTREAM_REPO))]
30+
upstream: String,
2631
#[clap(long, default_value(DEFAULT_CONFIG_PATH))]
2732
config_path: PathBuf,
2833
#[clap(long, default_value(DEFAULT_RUST_VERSION_PATH))]
@@ -69,11 +74,12 @@ fn main() -> anyhow::Result<()> {
6974
Command::Pull {
7075
config_path,
7176
rust_version_path,
77+
upstream,
7278
} => {
7379
let ctx = load_context(&config_path, &rust_version_path)?;
7480
let josh = get_josh_proxy()?;
7581
let sync = GitSync::new(ctx.clone(), josh);
76-
match sync.rustc_pull() {
82+
match sync.rustc_pull(upstream) {
7783
Ok(result) => {
7884
if !maybe_create_gh_pr(
7985
&ctx.config.full_repo_name(),
@@ -124,7 +130,7 @@ r? @ghost"#,
124130

125131
println!(
126132
r#"You can create the rustc PR using the following URL:
127-
https://github.com/{UPSTREAM_REPO}/compare/{username}:{branch}?quick_pull=1&title={}&body={}"#,
133+
https://github.com/{DEFAULT_UPSTREAM_REPO}/compare/{username}:{branch}?quick_pull=1&title={}&body={}"#,
128134
urlencoding::encode(&title),
129135
urlencoding::encode(&merge_msg)
130136
);

src/sync.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::utils::{run_command, stream_command};
66
use anyhow::{Context, Error};
77
use std::path::{Path, PathBuf};
88

9-
pub const UPSTREAM_REPO: &str = "rust-lang/rust";
9+
pub const DEFAULT_UPSTREAM_REPO: &str = "rust-lang/rust";
1010

1111
pub enum RustcPullError {
1212
/// No changes are available to be pulled.
@@ -35,13 +35,13 @@ impl GitSync {
3535
Self { context, proxy }
3636
}
3737

38-
pub fn rustc_pull(&self) -> Result<PullResult, RustcPullError> {
38+
pub fn rustc_pull(&self, upstream_repo: String) -> Result<PullResult, RustcPullError> {
3939
// The upstream commit that we want to pull
4040
let upstream_sha = {
4141
let out = run_command([
4242
"git",
4343
"ls-remote",
44-
&format!("https://github.com/{UPSTREAM_REPO}"),
44+
&format!("https://github.com/{upstream_repo}"),
4545
"HEAD",
4646
])
4747
.context("cannot fetch upstream commit")?;
@@ -59,7 +59,7 @@ impl GitSync {
5959
.start(&self.context.config)
6060
.context("cannot start josh-proxy")?;
6161
let josh_url = josh.git_url(
62-
UPSTREAM_REPO,
62+
&upstream_repo,
6363
Some(&upstream_sha),
6464
&self.context.config.construct_josh_filter(),
6565
);
@@ -98,7 +98,7 @@ impl GitSync {
9898
})?;
9999

100100
let prep_message = format!(
101-
r#"Prepare for merging from {UPSTREAM_REPO}
101+
r#"Prepare for merging from {upstream_repo}
102102
103103
This updates the rust-version file to {upstream_sha}."#,
104104
);
@@ -144,9 +144,9 @@ This updates the rust-version file to {upstream_sha}."#,
144144
println!("incoming ref: {incoming_ref}");
145145

146146
let merge_message = format!(
147-
r#"Merge ref '{upstream_head_short}' from {UPSTREAM_REPO}
147+
r#"Merge ref '{upstream_head_short}' from {upstream_repo}
148148
149-
Pull recent changes from https://github.com/{UPSTREAM_REPO} via Josh.
149+
Pull recent changes from https://github.com/{upstream_repo} via Josh.
150150
151151
Upstream ref: {upstream_sha}
152152
Filtered ref: {incoming_ref}
@@ -241,7 +241,7 @@ This merge was created using https://github.com/rust-lang/josh-sync.
241241
&[
242242
"git",
243243
"fetch",
244-
&format!("https://github.com/{UPSTREAM_REPO}"),
244+
&format!("https://github.com/{DEFAULT_UPSTREAM_REPO}"),
245245
&base_upstream_sha,
246246
],
247247
&rustc_git,

0 commit comments

Comments
 (0)