cli: add a --dry-run for jj git push

This commit is contained in:
Martin von Zweigbergk 2022-06-28 19:10:45 -07:00 committed by Martin von Zweigbergk
parent c10c510e01
commit 7a99257040
2 changed files with 17 additions and 1 deletions

View File

@ -1875,6 +1875,9 @@ struct GitPushArgs {
/// Push this commit by creating a branch based on its change ID
#[clap(long)]
change: Option<String>,
/// Only display what will change on the remote
#[clap(long)]
dry_run: bool,
}
/// Update repo with changes made in the underlying Git repo
@ -5233,6 +5236,11 @@ fn cmd_git_push(
}
}
if args.dry_run {
writeln!(ui, "Dry-run requested, not pushing.")?;
return Ok(());
}
let git_repo = get_git_repo(repo.store())?;
git::push_updates(&git_repo, &args.remote, &ref_updates)
.map_err(|err| CommandError::UserError(err.to_string()))?;

View File

@ -89,7 +89,15 @@ fn test_git_push_success() {
@origin (ahead by 1 commits, behind by 1 commits): 545acdb23f70 description
my-branch: 7840c9885676 foo
"###);
// First dry-run
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--dry-run"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
Delete branch branch1 from 545acdb23f70
Move branch branch2 from 545acdb23f70 to 7840c9885676
Add branch my-branch to 7840c9885676
Dry-run requested, not pushing.
"###);
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin: