-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: port description template to templater
This implements a building block of "signed-off-by line" #1399 and "commit --verbose" #1946. We'll probably need an easy way to customize the diff part, but I'm not sure if it can be as simple as a template alias function. User might want to embed diffs without "JJ: " prefixes? Perhaps, we can deprecate "ui.default-description", but it's not addressed in this patch. It could be replaced with "default_description" template alias, but we might want to configure default per command. Suppose we add a default "backout_description" template, it would have to be rendered against the source commit, not the newly-created backout commit. The template key is named as "draft_commit_description" because it is the template to generate an editor template. "templates.commit_description_template" sounds a bit odd. There's one minor behavior change: the default description is now terminated by "\n". Closes #1354
- Loading branch information
Showing
11 changed files
with
130 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,6 +174,7 @@ fn test_commit_with_default_description() { | |
TESTED=TODO | ||
JJ: This commit contains the following changes: | ||
JJ: A file1 | ||
JJ: A file2 | ||
|
@@ -182,6 +183,67 @@ fn test_commit_with_default_description() { | |
"###); | ||
} | ||
|
||
#[test] | ||
fn test_commit_with_description_template() { | ||
let mut test_env = TestEnvironment::default(); | ||
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); | ||
test_env.add_config( | ||
r#" | ||
[templates] | ||
draft_commit_description = ''' | ||
concat( | ||
description, | ||
"\n", | ||
indent( | ||
"JJ: ", | ||
concat( | ||
"Author: " ++ format_detailed_signature(author) ++ "\n", | ||
"Committer: " ++ format_detailed_signature(committer) ++ "\n", | ||
"\n", | ||
diff.stat(76), | ||
), | ||
), | ||
) | ||
''' | ||
"#, | ||
); | ||
let workspace_path = test_env.env_root().join("repo"); | ||
|
||
let edit_script = test_env.set_up_fake_editor(); | ||
std::fs::write(edit_script, ["dump editor"].join("\0")).unwrap(); | ||
|
||
std::fs::write(workspace_path.join("file1"), "foo\n").unwrap(); | ||
std::fs::write(workspace_path.join("file2"), "bar\n").unwrap(); | ||
|
||
// Only file1 should be included in the diff | ||
test_env.jj_cmd_ok(&workspace_path, &["commit", "file1"]); | ||
insta::assert_snapshot!( | ||
std::fs::read_to_string(test_env.env_root().join("editor")).unwrap(), @r###" | ||
JJ: Author: Test User <[email protected]> (2001-02-03 08:05:08) | ||
JJ: Committer: Test User <[email protected]> (2001-02-03 08:05:08) | ||
JJ: file1 | 1 + | ||
JJ: 1 file changed, 1 insertion(+), 0 deletions(-) | ||
JJ: Lines starting with "JJ: " (like this one) will be removed. | ||
"###); | ||
|
||
// Timestamp after the reset should be available to the template | ||
test_env.jj_cmd_ok(&workspace_path, &["commit", "--reset-author"]); | ||
insta::assert_snapshot!( | ||
std::fs::read_to_string(test_env.env_root().join("editor")).unwrap(), @r###" | ||
JJ: Author: Test User <[email protected]> (2001-02-03 08:05:09) | ||
JJ: Committer: Test User <[email protected]> (2001-02-03 08:05:09) | ||
JJ: file2 | 1 + | ||
JJ: 1 file changed, 1 insertion(+), 0 deletions(-) | ||
JJ: Lines starting with "JJ: " (like this one) will be removed. | ||
"###); | ||
} | ||
|
||
#[test] | ||
fn test_commit_without_working_copy() { | ||
let test_env = TestEnvironment::default(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters