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

feat(submit): support multiple revset arguments #1244

Merged
merged 1 commit into from
Feb 18, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- This allows `git sync my-branch` to work as expected, instead of needing to use `git sync 'stack(my-branch)'`. The behavior of `git sync` when called without arguments is not affected by this change. If you rely on the previous behavior, please use `git move -x <commit(s)/revset> -d 'main()'` instead.
- (#1169) `git record` now accepts multible `--message` arguments.
- (#1130) `branches()` revset function now accepts an optional text pattern argument to limit which branches are matched.
- (#1244) `git submit` now accepts multiple argements/revsets

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion git-branchless-opts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ pub struct SubmitArgs {
/// The commits to push. All branches attached to those commits will be
/// pushed.
#[clap(value_parser, default_value = "stack()")]
pub revset: Revset,
pub revsets: Vec<Revset>,

/// Options for resolving revset expressions.
#[clap(flatten)]
Expand Down
32 changes: 14 additions & 18 deletions git-branchless-submit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use git_branchless_test::{RawTestOptions, ResolvedTestOptions, Verbosity};
use github::GithubForge;
use itertools::Itertools;
use lazy_static::lazy_static;
use lib::core::dag::{CommitSet, Dag};
use lib::core::dag::{union_all, CommitSet, Dag};
use lib::core::effects::Effects;
use lib::core::eventlog::{EventLogDb, EventReplayer};
use lib::core::formatting::{Pluralize, StyledStringBuilder};
Expand Down Expand Up @@ -188,7 +188,7 @@ pub fn command_main(ctx: CommandContext, args: SubmitArgs) -> EyreExitOr<()> {
create,
draft,
strategy,
revset,
revsets,
resolve_revset_options,
forge,
message,
Expand All @@ -197,7 +197,7 @@ pub fn command_main(ctx: CommandContext, args: SubmitArgs) -> EyreExitOr<()> {
submit(
&effects,
&git_run_info,
revset,
revsets,
&resolve_revset_options,
create,
draft,
Expand All @@ -211,7 +211,7 @@ pub fn command_main(ctx: CommandContext, args: SubmitArgs) -> EyreExitOr<()> {
fn submit(
effects: &Effects,
git_run_info: &GitRunInfo,
revset: Revset,
revsets: Vec<Revset>,
resolve_revset_options: &ResolveRevsetOptions,
create: bool,
draft: bool,
Expand All @@ -234,19 +234,14 @@ fn submit(
&references_snapshot,
)?;

let commit_set = match resolve_commits(
effects,
&repo,
&mut dag,
&[revset.clone()],
resolve_revset_options,
) {
Ok(mut commit_sets) => commit_sets.pop().unwrap(),
Err(err) => {
err.describe(effects)?;
return Ok(Err(ExitCode(1)));
}
};
let commit_set =
match resolve_commits(effects, &repo, &mut dag, &revsets, resolve_revset_options) {
Ok(commit_sets) => union_all(&commit_sets),
Err(err) => {
err.describe(effects)?;
return Ok(Err(ExitCode(1)));
}
};

let raw_test_options = RawTestOptions {
exec: Some("<dummy>".to_string()),
Expand Down Expand Up @@ -294,14 +289,15 @@ fn submit(
message,
};

let unioned_revset = Revset(revsets.iter().map(|Revset(inner)| inner).join(" + "));
let mut forge = select_forge(
effects,
git_run_info,
&repo,
&mut dag,
&event_log_db,
&references_snapshot,
&revset,
&unioned_revset,
forge_kind,
);
let statuses = try_exit_code!(forge.query_status(commit_set)?);
Expand Down
22 changes: 22 additions & 0 deletions git-branchless-submit/tests/test_submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ fn test_submit() -> eyre::Result<()> {
"###);
}

// test handling of revset argument (should be identical to above)
{
let (stdout, stderr) = cloned_repo.run(&["submit", "bar+qux"])?;
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(stdout, @r###"
Skipped 2 commits (not yet on remote): bar, qux
These commits were skipped because they were not already associated with a remote
repository. To submit them, retry this operation with the --create option.
"###);
}

// test handling of multiple revset arguments (should be identical to above)
{
let (stdout, stderr) = cloned_repo.run(&["submit", "bar", "qux"])?;
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(stdout, @r###"
Skipped 2 commits (not yet on remote): bar, qux
These commits were skipped because they were not already associated with a remote
repository. To submit them, retry this operation with the --create option.
"###);
}

{
let (stdout, stderr) = cloned_repo.run(&["submit", "--dry-run"])?;
insta::assert_snapshot!(stderr, @"");
Expand Down
Loading