Skip to content

Commit

Permalink
git: add --allow-private option to push command
Browse files Browse the repository at this point in the history
  • Loading branch information
jennings committed Jul 23, 2024
1 parent 03b6d38 commit 2a9fdba
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cli/src/commands/git/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RevisionArg>,
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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 <REVISIONS>` — Push branches pointing to these commits (can be repeated)
* `-c`, `--change <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
Expand Down
28 changes: 28 additions & 0 deletions cli/tests/test_git_private_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 2a9fdba

Please sign in to comment.