forked from mirrors/jj
git: add --allow-private option to push command
This commit is contained in:
parent
03b6d380f5
commit
2a9fdbac52
3 changed files with 33 additions and 1 deletions
|
@ -93,6 +93,9 @@ pub struct GitPushArgs {
|
||||||
/// Allow pushing commits with empty descriptions
|
/// Allow pushing commits with empty descriptions
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
allow_empty_description: bool,
|
allow_empty_description: bool,
|
||||||
|
/// Allow pushing commits that are private
|
||||||
|
#[arg(long)]
|
||||||
|
allow_private: bool,
|
||||||
/// Push branches pointing to these commits (can be repeated)
|
/// Push branches pointing to these commits (can be repeated)
|
||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
revisions: Vec<RevisionArg>,
|
revisions: Vec<RevisionArg>,
|
||||||
|
@ -400,7 +403,7 @@ fn validate_commits_ready_to_push(
|
||||||
if commit.has_conflict()? {
|
if commit.has_conflict()? {
|
||||||
reasons.push("it has conflicts");
|
reasons.push("it has conflicts");
|
||||||
}
|
}
|
||||||
if is_private(commit.id()) {
|
if !args.allow_private && is_private(commit.id()) {
|
||||||
reasons.push("it is private");
|
reasons.push("it is private");
|
||||||
}
|
}
|
||||||
if !reasons.is_empty() {
|
if !reasons.is_empty() {
|
||||||
|
|
|
@ -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.
|
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-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)
|
* `-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)
|
* `-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
|
* `--dry-run` — Only display what will change on the remote
|
||||||
|
|
|
@ -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]
|
#[test]
|
||||||
fn test_git_private_commits_are_not_checked_if_immutable() {
|
fn test_git_private_commits_are_not_checked_if_immutable() {
|
||||||
let (test_env, workspace_root) = set_up();
|
let (test_env, workspace_root) = set_up();
|
||||||
|
|
Loading…
Reference in a new issue