Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] - ReleaseDate

### Added

- (#1129) Added a `--dry-run` option to `git submit` to report what would be submitted without actually doing so.

## [v0.8.0] - 2023-08-27

### Added
Expand Down
5 changes: 5 additions & 0 deletions git-branchless-opts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,11 @@ pub struct SubmitArgs {
/// An optional message to include with the create or update operation.
#[clap(short = 'm', long = "message")]
pub message: Option<String>,

/// Don't push or create anything. Instead, report what would be pushed or
/// created. (Still triggers a fetch.)
#[clap(short = 'n', long = "dry-run")]
pub dry_run: bool,
}

/// Run a command on each commit in a given set and aggregate the results.
Expand Down
27 changes: 20 additions & 7 deletions git-branchless-submit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ pub fn command_main(ctx: CommandContext, args: SubmitArgs) -> EyreExitOr<()> {
resolve_revset_options,
forge,
message,
dry_run,
} = args;
submit(
&effects,
Expand All @@ -169,6 +170,7 @@ pub fn command_main(ctx: CommandContext, args: SubmitArgs) -> EyreExitOr<()> {
strategy,
forge,
message,
dry_run,
)
}

Expand All @@ -182,6 +184,7 @@ fn submit(
execution_strategy: Option<TestExecutionStrategy>,
forge_kind: Option<ForgeKind>,
message: Option<String>,
dry_run: bool,
) -> EyreExitOr<()> {
let repo = Repo::from_current_dir()?;
let conn = repo.get_db_conn()?;
Expand Down Expand Up @@ -329,6 +332,8 @@ fn submit(
.collect();
if unsubmitted_commits.is_empty() {
Default::default()
} else if create && dry_run {
(unsubmitted_branches, Default::default())
} else if create {
let create_statuses =
try_exit_code!(forge.create(unsubmitted_commits, &submit_options)?);
Expand Down Expand Up @@ -371,14 +376,17 @@ fn submit(
.flat_map(|(_commit_oid, commit_status)| commit_status.local_branch_name.clone())
.collect();

try_exit_code!(forge.update(commits_to_update, &submit_options)?);
if !dry_run {
try_exit_code!(forge.update(commits_to_update, &submit_options)?);
}
(updated_branch_names, skipped_branch_names)
};

if !created_branches.is_empty() {
writeln!(
effects.get_output_stream(),
"Created {}: {}",
"{} {}: {}",
if dry_run { "Would create" } else { "Created" },
Pluralize {
determiner: None,
amount: created_branches.len(),
Expand All @@ -400,7 +408,8 @@ fn submit(
if !updated_branch_names.is_empty() {
writeln!(
effects.get_output_stream(),
"Pushed {}: {}",
"{} {}: {}",
if dry_run { "Would push" } else { "Pushed" },
Pluralize {
determiner: None,
amount: updated_branch_names.len(),
Expand All @@ -422,7 +431,8 @@ fn submit(
if !skipped_branch_names.is_empty() {
writeln!(
effects.get_output_stream(),
"Skipped {} (already up-to-date): {}",
"{} {} (already up-to-date): {}",
if dry_run { "Would skip" } else { "Skipped" },
Pluralize {
determiner: None,
amount: skipped_branch_names.len(),
Expand All @@ -444,7 +454,8 @@ fn submit(
if !uncreated_branches.is_empty() {
writeln!(
effects.get_output_stream(),
"Skipped {} (not yet on remote): {}",
"{} {} (not yet on remote): {}",
if dry_run { "Would skip" } else { "Skipped" },
Pluralize {
determiner: None,
amount: uncreated_branches.len(),
Expand All @@ -465,8 +476,10 @@ fn submit(
writeln!(
effects.get_output_stream(),
"\
These branches were skipped because they were not already associated with a remote repository. To
create and push them, retry this operation with the --create option."
These branches {} skipped because they {} not already associated with a remote repository. To
create and push them, retry this operation with the --create option.",
if dry_run { "would be" } else { "were" },
if dry_run { "are" } else { "were" },
)?;
}

Expand Down
18 changes: 18 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,24 @@ fn test_submit() -> eyre::Result<()> {
"###);
}

{
let (stdout, stderr) = cloned_repo.run(&["submit", "--dry-run"])?;
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(stdout, @r###"
Would skip 2 branches (not yet on remote): bar, qux
These branches would be skipped because they are not already associated with a remote repository. To
create and push them, retry this operation with the --create option.
"###);
}

{
let (stdout, stderr) = cloned_repo.run(&["submit", "--create", "--dry-run"])?;
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(stdout, @r###"
Would create 2 branches: bar, qux
"###);
}

{
let (stdout, stderr) = cloned_repo.run(&["submit", "--create"])?;
let stderr = redact_remotes(stderr);
Expand Down