From 8901396bfe8b7d9934ff8b3fcb22af69bf8aae48 Mon Sep 17 00:00:00 2001 From: Frank Benkstein Date: Sun, 22 Dec 2024 11:19:23 +0100 Subject: [PATCH 1/2] tests: add test for rebase without arguments Signed-off-by: Frank Benkstein --- t/t2200-rebase.sh | 5 +++++ t/test-lib-functions.sh | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/t/t2200-rebase.sh b/t/t2200-rebase.sh index 53d0ed0f..37e11e88 100755 --- a/t/t2200-rebase.sh +++ b/t/t2200-rebase.sh @@ -43,4 +43,9 @@ test_expect_success 'Rebase to same base message' ' grep "info: Already based on .*(master)" out ' +test_expect_success 'Rebase without argument' ' + test_must_fail stg rebase 2>out && + grep -q "error: the following required arguments were not provided" out +' + test_done diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 90034dfb..621cd9bf 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1024,7 +1024,7 @@ test_must_fail_acceptable () { fi case "$1" in - git|__git*|scalar|test-tool|fake_tool|test_terminal) + git|__git*|scalar|test-tool|fake_tool|test_terminal|stg) return 0 ;; *) From 9e747c2fe42bd4e0d451f2b9d74e986260724c3e Mon Sep 17 00:00:00 2001 From: Frank Benkstein Date: Tue, 24 Dec 2024 09:09:49 +0100 Subject: [PATCH 2/2] feat: support calling stg rebase without arguments 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. This slightly changes the behavior of `stg rebase --interactive`: previously when called without argument it would rebase onto the stack base, now it will rebase onto the upstream branch. Signed-off-by: Frank Benkstein --- src/cmd/rebase.rs | 38 +++++++++++++++++++++++++++++--------- t/t2200-rebase.sh | 15 ++++++++++++++- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/cmd/rebase.rs b/src/cmd/rebase.rs index 1f87f624..82a3a213 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,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::("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::("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=/ {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