Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support calling stg rebase without arguments #507

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 18 additions & 0 deletions t/t2200-rebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,22 @@ 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: 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
2 changes: 1 addition & 1 deletion t/test-lib-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
*)
Expand Down
Loading