From 7a99257040618bf85ae039ce552767d68bc9fa76 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Tue, 28 Jun 2022 19:10:45 -0700 Subject: [PATCH] cli: add a `--dry-run` for `jj git push` --- src/commands.rs | 8 ++++++++ tests/test_git_push.rs | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/commands.rs b/src/commands.rs index 08f3605ba..549d0f798 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1875,6 +1875,9 @@ struct GitPushArgs { /// Push this commit by creating a branch based on its change ID #[clap(long)] change: Option, + /// 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()))?; diff --git a/tests/test_git_push.rs b/tests/test_git_push.rs index ae8609dad..c17fa4d8f 100644 --- a/tests/test_git_push.rs +++ b/tests/test_git_push.rs @@ -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: