Skip to content

Commit

Permalink
support calling stg rebase without arguments
Browse files Browse the repository at this point in the history
When calling "git rebase" without a target commit argument then it will
try to look up remote tracking branch and rebase onto that. This change
makes "stg rebase" behave the same way. Note that this introduces a
slight discrepancy with "stg rebase --interactive": in this case it will
still use the stack base instead of the remote tracking branch.

Signed-off-by: Frank Benkstein <[email protected]>
  • Loading branch information
fbenkstein committed Dec 20, 2024
1 parent 5c35432 commit b7fc2e2
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/cmd/rebase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -99,15 +98,36 @@ 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::<SingleRevisionSpec>("committish") {
target_rev_spec.resolve(&repo, Some(&stack))?.commit
} else {
stack.base().clone()
};
let target_commit = if let Some(target_rev_spec) =
matches.get_one::<SingleRevisionSpec>("committish")
{
target_rev_spec.resolve(&repo, Some(&stack))?.commit
} 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=<remote>/<branch> {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!(
Expand Down

0 comments on commit b7fc2e2

Please sign in to comment.