Skip to content

Commit efad4c2

Browse files
feat(submit): support multiple revset arguments
Other commands, for example `git sync`, also accept multiple revset arguments.
1 parent 9858ab0 commit efad4c2

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- 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.
2121
- (#1169) `git record` now accepts multible `--message` arguments.
2222
- (#1130) `branches()` revset function now accepts an optional text pattern argument to limit which branches are matched.
23+
- (#1244) `git submit` now accepts multiple argements/revsets
2324

2425
### Fixed
2526

git-branchless-opts/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ pub struct SubmitArgs {
387387
/// The commits to push. All branches attached to those commits will be
388388
/// pushed.
389389
#[clap(value_parser, default_value = "stack()")]
390-
pub revset: Revset,
390+
pub revsets: Vec<Revset>,
391391

392392
/// Options for resolving revset expressions.
393393
#[clap(flatten)]

git-branchless-submit/src/lib.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use git_branchless_test::{RawTestOptions, ResolvedTestOptions, Verbosity};
2424
use github::GithubForge;
2525
use itertools::Itertools;
2626
use lazy_static::lazy_static;
27-
use lib::core::dag::{CommitSet, Dag};
27+
use lib::core::dag::{union_all, CommitSet, Dag};
2828
use lib::core::effects::Effects;
2929
use lib::core::eventlog::{EventLogDb, EventReplayer};
3030
use lib::core::formatting::{Pluralize, StyledStringBuilder};
@@ -188,7 +188,7 @@ pub fn command_main(ctx: CommandContext, args: SubmitArgs) -> EyreExitOr<()> {
188188
create,
189189
draft,
190190
strategy,
191-
revset,
191+
revsets,
192192
resolve_revset_options,
193193
forge,
194194
message,
@@ -197,7 +197,7 @@ pub fn command_main(ctx: CommandContext, args: SubmitArgs) -> EyreExitOr<()> {
197197
submit(
198198
&effects,
199199
&git_run_info,
200-
revset,
200+
revsets,
201201
&resolve_revset_options,
202202
create,
203203
draft,
@@ -211,7 +211,7 @@ pub fn command_main(ctx: CommandContext, args: SubmitArgs) -> EyreExitOr<()> {
211211
fn submit(
212212
effects: &Effects,
213213
git_run_info: &GitRunInfo,
214-
revset: Revset,
214+
revsets: Vec<Revset>,
215215
resolve_revset_options: &ResolveRevsetOptions,
216216
create: bool,
217217
draft: bool,
@@ -234,19 +234,14 @@ fn submit(
234234
&references_snapshot,
235235
)?;
236236

237-
let commit_set = match resolve_commits(
238-
effects,
239-
&repo,
240-
&mut dag,
241-
&[revset.clone()],
242-
resolve_revset_options,
243-
) {
244-
Ok(mut commit_sets) => commit_sets.pop().unwrap(),
245-
Err(err) => {
246-
err.describe(effects)?;
247-
return Ok(Err(ExitCode(1)));
248-
}
249-
};
237+
let commit_set =
238+
match resolve_commits(effects, &repo, &mut dag, &revsets, resolve_revset_options) {
239+
Ok(commit_sets) => union_all(&commit_sets),
240+
Err(err) => {
241+
err.describe(effects)?;
242+
return Ok(Err(ExitCode(1)));
243+
}
244+
};
250245

251246
let raw_test_options = RawTestOptions {
252247
exec: Some("<dummy>".to_string()),
@@ -294,14 +289,15 @@ fn submit(
294289
message,
295290
};
296291

292+
let unioned_revset = Revset(revsets.iter().map(|Revset(inner)| inner).join(" + "));
297293
let mut forge = select_forge(
298294
effects,
299295
git_run_info,
300296
&repo,
301297
&mut dag,
302298
&event_log_db,
303299
&references_snapshot,
304-
&revset,
300+
&unioned_revset,
305301
forge_kind,
306302
);
307303
let statuses = try_exit_code!(forge.query_status(commit_set)?);

git-branchless-submit/tests/test_submit.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@ fn test_submit() -> eyre::Result<()> {
6464
"###);
6565
}
6666

67+
// test handling of revset argument (should be identical to above)
68+
{
69+
let (stdout, stderr) = cloned_repo.run(&["submit", "bar+qux"])?;
70+
insta::assert_snapshot!(stderr, @"");
71+
insta::assert_snapshot!(stdout, @r###"
72+
Skipped 2 commits (not yet on remote): bar, qux
73+
These commits were skipped because they were not already associated with a remote
74+
repository. To submit them, retry this operation with the --create option.
75+
"###);
76+
}
77+
78+
// test handling of multiple revset arguments (should be identical to above)
79+
{
80+
let (stdout, stderr) = cloned_repo.run(&["submit", "bar", "qux"])?;
81+
insta::assert_snapshot!(stderr, @"");
82+
insta::assert_snapshot!(stdout, @r###"
83+
Skipped 2 commits (not yet on remote): bar, qux
84+
These commits were skipped because they were not already associated with a remote
85+
repository. To submit them, retry this operation with the --create option.
86+
"###);
87+
}
88+
6789
{
6890
let (stdout, stderr) = cloned_repo.run(&["submit", "--dry-run"])?;
6991
insta::assert_snapshot!(stderr, @"");

0 commit comments

Comments
 (0)