diff --git a/src/cmd/rebase.rs b/src/cmd/rebase.rs index 1f87f624..5ed4a7dd 100644 --- a/src/cmd/rebase.rs +++ b/src/cmd/rebase.rs @@ -49,8 +49,7 @@ fn make() -> clap::Command { .arg( Arg::new("committish") .help("New base commit for the stack") - .value_parser(clap::value_parser!(SingleRevisionSpec)) - .required_unless_present("interactive"), + .value_parser(clap::value_parser!(SingleRevisionSpec)), ) .arg( Arg::new("interactive") @@ -99,15 +98,35 @@ fn run(matches: &ArgMatches) -> Result<()> { let branch_name = stack.get_branch_name().to_string(); let allow_push_conflicts = argset::resolve_allow_push_conflicts(&config, matches); let committer_date_is_author_date = matches.get_flag("committer-date-is-author-date"); + let interactive = matches.get_flag("interactive"); let target_commit = if let Some(target_rev_spec) = matches.get_one::("committish") { target_rev_spec.resolve(&repo, Some(&stack))?.commit - } else { + } else if let Some(remote_ref) = repo + .branch_remote_tracking_ref_name(stack.get_branch_refname(), gix::remote::Direction::Fetch) + .transpose()? + { + let id = repo.rev_parse_single(remote_ref.as_bstr())?; + id.object()?.into_commit().into() + } else if interactive { stack.base().clone() + } else { + print_info_message( + matches, + &format!( + "if you wish to set tracking information for this branch you can do so with: + + git branch --set-upstream-to=/ {branch_name} +" + ), + ); + return Err(anyhow!( + "there is no tracking information for the current branch" + )); }; - if !matches.get_flag("interactive") && target_commit.id == stack.base().id { + if !interactive && target_commit.id == stack.base().id { print_info_message( matches, &format!( diff --git a/t/t2200-rebase.sh b/t/t2200-rebase.sh index 37e11e88..7161794a 100755 --- a/t/t2200-rebase.sh +++ b/t/t2200-rebase.sh @@ -45,7 +45,20 @@ test_expect_success 'Rebase to same base message' ' test_expect_success 'Rebase without argument' ' test_must_fail stg rebase 2>out && - grep -q "error: the following required arguments were not provided" out + grep -q "error: there is no tracking information for the current branch" out && + git checkout master && + echo bar >>file2 && + git add file2 && + git commit -m c && + git remote add origin "file://$(pwd)" && + git fetch origin && + git checkout stack && + git branch --set-upstream-to=origin/master && + stg rebase 2>out && + grep "info: Rebasing to .*(master origin/master)" out && + test $(stg series --applied -c) = 1 && + grep bar file1 && + grep bar file2 ' test_done