cli: add ui.signed-off-by = true to configure sign offs
Some checks failed
nix / flake check (push) Has been cancelled
build / build (, macos-13) (push) Has been cancelled
build / build (, macos-14) (push) Has been cancelled
build / build (, ubuntu-24.04) (push) Has been cancelled
build / build (, windows-latest) (push) Has been cancelled
build / build (--all-features, ubuntu-24.04) (push) Has been cancelled
build / Build without Git support (push) Has been cancelled
build / Check protos (push) Has been cancelled
build / Check formatting (push) Has been cancelled
build / Run doctests (push) Has been cancelled
build / Check that MkDocs can build the docs (push) Has been cancelled
build / Check that MkDocs can build the docs with latest Python and uv (push) Has been cancelled
build / cargo-deny (advisories) (push) Has been cancelled
build / cargo-deny (bans licenses sources) (push) Has been cancelled
build / Clippy check (push) Has been cancelled

Many of the desired features for the default commit template, notably
pre-populating things, can be solved with a simple pattern:

1. Inside `template-aliases.draft_commit_message`, use the following:

       if(config("name.space").as_boolean() && !description.contains("..."), ...)`

2. Set `name.space = true` in repos where you want it enabled.

This patch uses this idea to configure a new behavior to get
`Signed-off-by` lines included in their repositories.

While `Signed-off-by:` is a git mechanism, it is a common one and this
makes it easier to use jj OOTB with repositories that might require
those, without adding any more real surface area to the Rust codebase.
This general idea can be configured by the user though, e.g. for
`BUG=123` templates, or Gerrit `Change-Id`s, or other various things.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
This commit is contained in:
Austin Seipp 2025-01-07 15:30:20 -06:00
parent 9ed1fde364
commit 04630c5892
3 changed files with 36 additions and 0 deletions

View file

@ -33,6 +33,7 @@ quiet = false
log-word-wrap = false
log-synthetic-elided-nodes = true
conflict-marker-style = "diff"
signed-off-by = false
[ui.movement]
edit = false

View file

@ -32,6 +32,10 @@ if(overridden,
draft_commit_description = '''
concat(
description,
if(
config("ui.signed-off-by").as_boolean() && !description.contains("Signed-off-by: " ++ author.name()),
"\nSigned-off-by: " ++ author,
),
surround(
"\nJJ: This commit contains the following changes:\n", "",
indent("JJ: ", diff.summary()),

View file

@ -580,6 +580,37 @@ fn test_describe_default_description() {
"###);
}
#[test]
fn test_describe_signed_off() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
test_env.add_config(r#"ui.default-description = "\n\nTESTED=TODO""#);
test_env.add_config(r#"ui.signed-off-by = true"#);
let workspace_path = test_env.env_root().join("repo");
std::fs::write(workspace_path.join("file1"), "foo\n").unwrap();
std::fs::write(workspace_path.join("file2"), "bar\n").unwrap();
let edit_script = test_env.set_up_fake_editor();
std::fs::write(edit_script, ["dump editor"].join("\0")).unwrap();
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_path, &["describe"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Working copy now at: qpvuntsm 9b7a94ea TESTED=TODO
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"#);
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor")).unwrap(), @r#"
TESTED=TODO
Signed-off-by: Test User <test.user@example.com>
JJ: This commit contains the following changes:
JJ: A file1
JJ: A file2
JJ: Lines starting with "JJ:" (like this one) will be removed.
"#);
}
#[test]
fn test_describe_author() {
let mut test_env = TestEnvironment::default();