Skip to content

Commit

Permalink
cli: add --ignore-empty-description flag to push
Browse files Browse the repository at this point in the history
This commit adds an optional flag to be able to push commits with an
empty description to a remote git repo. While the default behavior is
ideal we might need to interact with a repo that has an empty commit
description in it. I ran into this issue a few weeks ago pushing commits
from an open source repo to an empty repo and had to go back to using
git for that push as I would not want to rewrite the history which was
many many years long just for that.

This flag allows users an escape hatch for pushing empty descriptions
for commits and they're sure that they want that behavior.

This commit adds the flag to the `git push` command and updates the docs
for the command. It also adds a new test to make sure that the flag
works as intended alongside the old test which makes sure to reject an
empty message for a commit.

Closes jj-vcs#2633
  • Loading branch information
mgattozzi committed May 9, 2024
1 parent 9a5b001 commit 0abc5f2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cli/src/commands/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ pub struct GitPushArgs {
/// correspond to missing local branches.
#[arg(long)]
deleted: bool,
/// Push branches that contain empty descriptions
#[arg(long)]
allow_empty_description: bool,
/// Push branches pointing to these commits (can be repeated)
#[arg(long, short)]
revisions: Vec<RevisionArg>,
Expand Down Expand Up @@ -930,7 +933,7 @@ fn cmd_git_push(
{
let commit = commit?;
let mut reasons = vec![];
if commit.description().is_empty() {
if commit.description().is_empty() && !args.allow_empty_description {
reasons.push("it has no description");
}
if commit.author().name.is_empty()
Expand Down
5 changes: 4 additions & 1 deletion cli/tests/[email protected]
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: cli/tests/test_generate_md_cli_help.rs
description: "AUTO-GENERATED FILE, DO NOT EDIT. This cli reference is generated as an `insta` snapshot. MkDocs follows they symlink from docs/cli-reference.md to the snap. Unfortunately, `insta` unavoidably creates this header. Luckily, MkDocs ignores the header since it has the same format as Markdown headers. TODO: MkDocs may fail on Windows if symlinks are not enabled in the OS settings"
---
<!-- BEGIN MARKDOWN-->

Expand Down Expand Up @@ -931,6 +930,10 @@ By default, pushes any branches pointing to `remote_branches(remote=<remote>)..@
Possible values: `true`, `false`
* `--allow-empty-description` — Push branches that contain empty descriptions
Possible values: `true`, `false`
* `-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
17 changes: 17 additions & 0 deletions cli/tests/test_git_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,23 @@ fn test_git_push_no_description() {
"###);
}

#[test]
fn test_git_allow_push_no_description() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "my-branch"]);
test_env.jj_cmd_ok(&workspace_root, &["describe", "-m="]);
test_env.jj_cmd_ok(
&workspace_root,
&[
"git",
"push",
"--branch",
"my-branch",
"--allow-empty-description",
],
);
}

#[test]
fn test_git_push_missing_author() {
let (test_env, workspace_root) = set_up();
Expand Down

0 comments on commit 0abc5f2

Please sign in to comment.