From 2a9fdbac52f3634c81ad0adb2ad39dd044439080 Mon Sep 17 00:00:00 2001 From: Stephen Jennings Date: Fri, 19 Jul 2024 15:53:21 -0700 Subject: [PATCH] git: add --allow-private option to push command --- cli/src/commands/git/push.rs | 5 ++++- cli/tests/cli-reference@.md.snap | 1 + cli/tests/test_git_private_commits.rs | 28 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cli/src/commands/git/push.rs b/cli/src/commands/git/push.rs index ba3e11dd5e..e0fbedb177 100644 --- a/cli/src/commands/git/push.rs +++ b/cli/src/commands/git/push.rs @@ -93,6 +93,9 @@ pub struct GitPushArgs { /// Allow pushing commits with empty descriptions #[arg(long)] allow_empty_description: bool, + /// Allow pushing commits that are private + #[arg(long)] + allow_private: bool, /// Push branches pointing to these commits (can be repeated) #[arg(long, short)] revisions: Vec, @@ -400,7 +403,7 @@ fn validate_commits_ready_to_push( if commit.has_conflict()? { reasons.push("it has conflicts"); } - if is_private(commit.id()) { + if !args.allow_private && is_private(commit.id()) { reasons.push("it is private"); } if !reasons.is_empty() { diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index cef02c2fcb..7a0ecfe0ab 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -945,6 +945,7 @@ Before the command actually moves, creates, or deletes a remote branch, it makes Only tracked branches can be successfully deleted on the remote. A warning will be printed if any untracked branches on the remote correspond to missing local branches. * `--allow-empty-description` — Allow pushing commits with empty descriptions +* `--allow-private` — Allow pushing commits that are private * `-r`, `--revisions ` — Push branches pointing to these commits (can be repeated) * `-c`, `--change ` — Push this commit by creating a branch based on its change ID (can be repeated) * `--dry-run` — Only display what will change on the remote diff --git a/cli/tests/test_git_private_commits.rs b/cli/tests/test_git_private_commits.rs index a1473ffb9f..173910635a 100644 --- a/cli/tests/test_git_private_commits.rs +++ b/cli/tests/test_git_private_commits.rs @@ -96,6 +96,34 @@ fn test_git_private_commits_block_pushing() { "###); } +#[test] +fn test_git_private_commits_can_be_overridden() { + let (test_env, workspace_root) = set_up(); + + test_env.jj_cmd_ok(&workspace_root, &["new", "main", "-m=private 1"]); + test_env.jj_cmd_ok(&workspace_root, &["branch", "set", "main"]); + + // Will not push when a pushed commit is contained in git.private-commits + test_env.add_config(r#"git.private-commits = "description(glob:'private*')""#); + let stderr = test_env.jj_cmd_failure(&workspace_root, &["git", "push", "--all"]); + insta::assert_snapshot!(stderr, @r###" + Error: Won't push commit aa3058ff8663 since it is private + "###); + + // May push when the commit is removed from git.private-commits + let (_, stderr) = test_env.jj_cmd_ok( + &workspace_root, + &["git", "push", "--all", "--allow-private"], + ); + insta::assert_snapshot!(stderr, @r###" + Branch changes to push to origin: + Move forward branch main from 7eb97bf230ad to aa3058ff8663 + Warning: The working-copy commit in workspace 'default' became immutable, so a new commit has been created on top of it. + Working copy now at: znkkpsqq 2e1adf47 (empty) (no description set) + Parent commit : yqosqzyt aa3058ff main | (empty) private 1 + "###); +} + #[test] fn test_git_private_commits_are_not_checked_if_immutable() { let (test_env, workspace_root) = set_up();