From a14f39c68c44593f6dd4c87ef3d822eee98d49c6 Mon Sep 17 00:00:00 2001 From: Michael Gattozzi Date: Thu, 9 May 2024 13:26:07 -0400 Subject: [PATCH] cli: add --allow-empty-description flag to push 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 updates the original test to make sure that the flag works as intended to reject the commit when not set and to allow the commit when the flag is set. Closes #2633 --- CHANGELOG.md | 3 +++ cli/src/commands/git.rs | 5 ++++- cli/tests/cli-reference@.md.snap | 4 ++++ cli/tests/test_git_push.rs | 10 ++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d10496145c..64b305839d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `ui.color = "debug"` prints active labels alongside the regular colored output. +* `jj git push` now can push commits with empty descriptions with the + `--allow-empty-description` flag + ### Fixed bugs * When the working copy commit becomes immutable, a new one is automatically created on top of it diff --git a/cli/src/commands/git.rs b/cli/src/commands/git.rs index 9f22ca7c4b..882ea170b7 100644 --- a/cli/src/commands/git.rs +++ b/cli/src/commands/git.rs @@ -220,6 +220,9 @@ pub struct GitPushArgs { /// correspond to missing local branches. #[arg(long)] deleted: bool, + /// Allow pushing commits with empty descriptions + #[arg(long)] + allow_empty_description: bool, /// Push branches pointing to these commits (can be repeated) #[arg(long, short)] revisions: Vec, @@ -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() diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index c74cbbfa50..1ed5815b20 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -932,6 +932,10 @@ By default, pushes any branches pointing to `remote_branches(remote=)..@ Possible values: `true`, `false` +* `--allow-empty-description` — Allow pushing commits with empty descriptions + + Possible values: `true`, `false` + * `-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_push.rs b/cli/tests/test_git_push.rs index 68ccada4ef..dfe11b3e8b 100644 --- a/cli/tests/test_git_push.rs +++ b/cli/tests/test_git_push.rs @@ -645,6 +645,16 @@ fn test_git_push_no_description() { insta::assert_snapshot!(stderr, @r###" Error: Won't push commit 5b36783cd11c since it has no description "###); + test_env.jj_cmd_ok( + &workspace_root, + &[ + "git", + "push", + "--branch", + "my-branch", + "--allow-empty-description", + ], + ); } #[test]