Skip to content
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
38 changes: 29 additions & 9 deletions src/bin/rustc_josh_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ enum Command {
/// If you instead want to exit successfully in that case, pass this flag.
#[clap(long)]
allow_noop: bool,

/// Print executed commands.
#[clap(long, short = 'v')]
verbose: bool,
},
/// Push changes into the main `rust-lang/rust` repository `branch` of a `rustc` fork under
/// the given GitHub `username`.
Expand All @@ -64,6 +68,10 @@ enum Command {

/// Your GitHub usename where the fork is located
username: String,

/// Print executed commands.
#[clap(long, short = 'v')]
verbose: bool,
},
}

Expand Down Expand Up @@ -91,15 +99,16 @@ fn main() -> anyhow::Result<()> {
}
}
Command::Pull {
verbose,
config_path,
rust_version_path,
upstream_repo,
upstream_commit,
allow_noop,
} => {
let ctx = load_context(&config_path, &rust_version_path)?;
let josh = get_josh_proxy()?;
let sync = GitSync::new(ctx.clone(), josh);
let josh = get_josh_proxy(verbose)?;
let sync = GitSync::new(ctx.clone(), josh, verbose);
match sync.rustc_pull(upstream_repo, upstream_commit) {
Ok(result) => {
if !maybe_create_gh_pr(
Expand All @@ -121,6 +130,9 @@ fn main() -> anyhow::Result<()> {
}
Err(RustcPullError::PullFailed(error)) => {
eprintln!("Pull failure: {error:?}");
if !verbose {
eprintln!("Rerun with `-v` to see executed commands");
}
std::process::exit(1);
}
}
Expand All @@ -130,16 +142,24 @@ fn main() -> anyhow::Result<()> {
branch,
config_path,
rust_version_path,
verbose,
} => {
let ctx = load_context(&config_path, &rust_version_path)?;
let josh = get_josh_proxy()?;
let sync = GitSync::new(ctx.clone(), josh);
sync.rustc_push(&username, &branch)
.context("cannot perform push")?;
let josh = get_josh_proxy(verbose)?;
let sync = GitSync::new(ctx.clone(), josh, verbose);
if let Err(error) = sync
.rustc_push(&username, &branch)
.context("cannot perform push")
{
if !verbose {
eprintln!("Rerun with `-v` to see executed commands");
}
return Err(error);
}

// Open PR with `subtree update` title to silence the `no-merges` triagebot check
let title = format!("{} subtree update", ctx.config.repo);
let head = get_current_head_sha()?;
let head = get_current_head_sha(verbose)?;

let merge_msg = format!(
r#"Subtree update of `{repo}` to https://github.com/{full_repo}/commit/{head}.
Expand Down Expand Up @@ -204,9 +224,9 @@ fn maybe_create_gh_pr(repo: &str, title: &str, description: &str) -> anyhow::Res
}
}

fn get_josh_proxy() -> anyhow::Result<JoshProxy> {
fn get_josh_proxy(verbose: bool) -> anyhow::Result<JoshProxy> {
println!("Updating/installing josh-proxy binary...");
match try_install_josh() {
match try_install_josh(verbose) {
Some(proxy) => Ok(proxy),
None => Err(anyhow::anyhow!("Could not install josh-proxy")),
}
Expand Down
25 changes: 14 additions & 11 deletions src/josh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ impl JoshProxy {
}

/// Try to install (or update) josh-proxy, to make sure that we use the correct version.
pub fn try_install_josh() -> Option<JoshProxy> {
run_command(&[
"cargo",
"install",
"--locked",
"--git",
"https://github.com/josh-project/josh",
"--tag",
JOSH_VERSION,
"josh-proxy",
])
pub fn try_install_josh(verbose: bool) -> Option<JoshProxy> {
run_command(
&[
"cargo",
"install",
"--locked",
"--git",
"https://github.com/josh-project/josh",
"--tag",
JOSH_VERSION,
"josh-proxy",
],
verbose,
)
.expect("cannot install josh-proxy");
JoshProxy::lookup()
}
Expand Down
Loading
Loading