fix(autorebase): enforce repo argument (#10)

This commit is contained in:
Luis H. Ball Jr 2021-11-18 11:06:49 -08:00 committed by GitHub
parent cd29468114
commit 5e92f21a90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 16 deletions

View File

@ -51,15 +51,15 @@ fn clap<'a, 'b>() -> App<'a, 'b> {
let autorebase = SubCommand::with_name("autorebase") let autorebase = SubCommand::with_name("autorebase")
.about("Rebuild a stack based on changes to local branches and mirror these changes up to the remote") .about("Rebuild a stack based on changes to local branches and mirror these changes up to the remote")
.arg(Arg::with_name("remote") .arg(Arg::with_name("origin")
.long("remote") .long("origin")
.short("r") .short("o")
.value_name("REMOTE") .value_name("ORIGIN")
.help("Name of the remote to (force-)push the updated stack to (default: `origin`)")) .help("Name of the origin to (force-)push the updated stack to (default: `origin`)"))
.arg(Arg::with_name("repo") .arg(Arg::with_name("project")
.long("repo") .long("project")
.short("C") .short("C")
.value_name("PATH_TO_REPO") .value_name("PATH_TO_PROJECT")
.help("Path to a local copy of the repository")) .help("Path to a local copy of the repository"))
.arg(Arg::with_name("boundary") .arg(Arg::with_name("boundary")
.long("initial-cherry-pick-boundary") .long("initial-cherry-pick-boundary")
@ -68,6 +68,7 @@ fn clap<'a, 'b>() -> App<'a, 'b> {
.help("Stop the initial cherry-pick at this SHA (exclusive)")) .help("Stop the initial cherry-pick at this SHA (exclusive)"))
.setting(AppSettings::ArgRequiredElseHelp) .setting(AppSettings::ArgRequiredElseHelp)
.arg(exclude.clone()) .arg(exclude.clone())
.arg(repository.clone())
.arg(identifier.clone()); .arg(identifier.clone());
let rebase = SubCommand::with_name("rebase") let rebase = SubCommand::with_name("rebase")
@ -213,17 +214,26 @@ async fn main() -> Result<(), Box<dyn Error>> {
("autorebase", Some(m)) => { ("autorebase", Some(m)) => {
let identifier = m.value_of("identifier").unwrap(); let identifier = m.value_of("identifier").unwrap();
let stack = build_pr_stack(identifier, &credentials, get_excluded(m)).await?; // Log an error if repository is not specified.
m.value_of("repository").expect("The --repository argument is required.");
let repository = m.value_of("repository").unwrap();
println!(
"Searching for {} identifier in {} repo",
style(identifier).bold(),
style(repository).bold()
);
let stack = build_pr_stack_for_repo(identifier, repository, &credentials, get_excluded(m)).await?;
let repo = m let project = m
.value_of("repo") .value_of("project")
.expect("The --repo argument is required."); .expect("The --project argument is required.");
let repo = Repository::open(repo)?; let project = Repository::open(project)?;
let remote = m.value_of("remote").unwrap_or("origin"); // defaults to "origin" if no remote is specified
let remote = repo.find_remote(remote).unwrap(); let remote = m.value_of("origin").unwrap_or("origin");
let remote = project.find_remote(remote).unwrap();
git::perform_rebase(stack, &repo, remote.name().unwrap(), m.value_of("boundary")) git::perform_rebase(stack, &project, remote.name().unwrap(), m.value_of("boundary"))
.await?; .await?;
println!("All done!"); println!("All done!");
} }