Skip to content

Commit 1974cb5

Browse files
committed
Make josh-proxy installation unconditional
1 parent 49f3a58 commit 1974cb5

File tree

4 files changed

+10
-36
lines changed

4 files changed

+10
-36
lines changed

src/bin/josh_sync.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,9 @@ fn maybe_create_gh_pr(repo: &str, title: &str, description: &str) -> anyhow::Res
153153
}
154154

155155
fn get_josh_proxy() -> anyhow::Result<JoshProxy> {
156-
match JoshProxy::lookup() {
156+
println!("Updating/installing josh-proxy binary...");
157+
match try_install_josh() {
157158
Some(proxy) => Ok(proxy),
158-
None => {
159-
if prompt("josh-proxy not found. Do you want to install it?") {
160-
match try_install_josh() {
161-
Some(proxy) => Ok(proxy),
162-
None => Err(anyhow::anyhow!("Could not install josh-proxy")),
163-
}
164-
} else {
165-
Err(anyhow::anyhow!("josh-proxy could not be found"))
166-
}
167-
}
159+
None => Err(anyhow::anyhow!("Could not install josh-proxy")),
168160
}
169161
}

src/josh.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl JoshProxy {
6262
}
6363
}
6464

65+
/// Try to install (or update) josh-proxy, to make sure that we use the correct version.
6566
pub fn try_install_josh() -> Option<JoshProxy> {
6667
run_command(&[
6768
"cargo",

src/sync.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::SyncContext;
22
use crate::josh::JoshProxy;
3-
use crate::utils::{
4-
StderrMode, ensure_clean_git_state, replace_references, run_command, run_command_at,
5-
};
3+
use crate::utils::{ensure_clean_git_state, replace_references, run_command, run_command_at};
64
use anyhow::{Context, Error};
75
use std::path::{Path, PathBuf};
86

@@ -225,13 +223,7 @@ Filtered ref: {incoming_ref}
225223
println!("Preparing {user_upstream_url} (base: {base_upstream_sha})...");
226224

227225
// Check if the remote branch doesn't already exist
228-
if run_command_at(
229-
&["git", "fetch", &user_upstream_url, branch],
230-
&rustc_git,
231-
StderrMode::Print,
232-
)
233-
.is_ok()
234-
{
226+
if run_command_at(&["git", "fetch", &user_upstream_url, branch], &rustc_git).is_ok() {
235227
return Err(anyhow::anyhow!(
236228
"The branch '{branch}' seems to already exist in '{user_upstream_url}'. Please delete it and try again."
237229
));
@@ -246,7 +238,6 @@ Filtered ref: {incoming_ref}
246238
&base_upstream_sha,
247239
],
248240
&rustc_git,
249-
StderrMode::Print,
250241
)
251242
.context("cannot download latest upstream SHA")?;
252243

@@ -259,7 +250,6 @@ Filtered ref: {incoming_ref}
259250
&format!("{base_upstream_sha}:refs/heads/{branch}"),
260251
],
261252
&rustc_git,
262-
StderrMode::Ignore,
263253
)
264254
.context("cannot push to your fork")?;
265255
println!();
@@ -273,7 +263,6 @@ Filtered ref: {incoming_ref}
273263
run_command_at(
274264
&["git", "fetch", &josh_url, &branch],
275265
&std::env::current_dir().unwrap(),
276-
StderrMode::Ignore,
277266
)?;
278267
let head = run_command(&["git", "rev-parse", "HEAD"])?;
279268
let fetch_head = run_command(&["git", "rev-parse", "FETCH_HEAD"])?;

src/utils.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
use regex::Regex;
22
use std::borrow::Cow;
33
use std::path::Path;
4-
use std::process::{Command, Stdio};
4+
use std::process::Command;
55

66
/// Run command and return its stdout.
77
pub fn run_command<'a, Args: AsRef<[&'a str]>>(args: Args) -> anyhow::Result<String> {
8-
run_command_at(args, &std::env::current_dir()?, StderrMode::Print)
9-
}
10-
11-
pub enum StderrMode {
12-
Ignore,
13-
Print,
8+
run_command_at(args, &std::env::current_dir()?)
149
}
1510

1611
pub fn run_command_at<'a, Args: AsRef<[&'a str]>>(
1712
args: Args,
1813
workdir: &Path,
19-
stderr: StderrMode,
2014
) -> anyhow::Result<String> {
2115
let args = args.as_ref();
2216

2317
let mut cmd = Command::new(args[0]);
2418
cmd.current_dir(workdir);
2519
cmd.args(&args[1..]);
2620

27-
if matches!(stderr, StderrMode::Ignore) {
28-
cmd.stderr(Stdio::null());
29-
}
3021
eprintln!("+ {cmd:?}");
3122
let out = cmd.output().expect("command failed");
3223
let stdout = String::from_utf8_lossy(out.stdout.trim_ascii()).to_string();
24+
let stderr = String::from_utf8_lossy(out.stderr.trim_ascii()).to_string();
3325
if !out.status.success() {
3426
Err(anyhow::anyhow!(
35-
"Command `{cmd:?}` failed with exit code {:?}. STDOUT:\n{stdout}",
27+
"Command `{cmd:?}` failed with exit code {:?}. STDOUT:\n{stdout}\nSTDERR:\n{stderr}",
3628
out.status.code()
3729
))
3830
} else {

0 commit comments

Comments
 (0)