mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-05 15:32:49 +00:00
templates: create new git_format_patch_email_headers template
With this template, a 'git format-patch' compatible email message can be generated using something like: jj show --git --template git_format_patch_email_headers <rev>
This commit is contained in:
parent
e67eba3abf
commit
24cd079307
@ -402,3 +402,21 @@ coalesce(
|
||||
"o",
|
||||
)
|
||||
'''
|
||||
|
||||
# The first line is a fixed magic date string used by
|
||||
# programs like file(1) to identify that this is output from
|
||||
# 'git format-patch'.
|
||||
# See https://git-scm.com/docs/git-format-patch#_description
|
||||
git_format_patch_email_headers = '''
|
||||
concat(
|
||||
"From " ++ commit_id ++ " Mon Sep 17 00:00:00 2001\n",
|
||||
"From: " ++ author ++ "\n",
|
||||
"Date: " ++ author.timestamp().format("%a, %-e %b %Y %T %z") ++ "\n",
|
||||
"Subject: [PATCH] " ++ description.first_line() ++ "\n",
|
||||
"\n",
|
||||
description.remove_prefix(description.first_line()).trim_start(),
|
||||
"---\n",
|
||||
indent(" ", diff.stat()),
|
||||
"\n"
|
||||
)
|
||||
'''
|
||||
|
@ -1609,3 +1609,49 @@ fn test_signature_templates() {
|
||||
[EOF]
|
||||
");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_log_git_format_patch_template() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
|
||||
let work_dir = test_env.work_dir("repo");
|
||||
|
||||
work_dir.write_file("file1", "foo\n");
|
||||
work_dir.write_file("file2", "bar\n");
|
||||
work_dir
|
||||
.run_jj([
|
||||
"new",
|
||||
"-m",
|
||||
"some change\n\nmultiline desc\nsecond line\n\nwith blanks\n",
|
||||
])
|
||||
.success();
|
||||
work_dir.remove_file("file1");
|
||||
work_dir.write_file("file2", "modified\n");
|
||||
work_dir.write_file("file3", "new\n");
|
||||
|
||||
let output = work_dir.run_jj([
|
||||
"log",
|
||||
"--no-graph",
|
||||
"-T",
|
||||
"git_format_patch_email_headers",
|
||||
"-r@",
|
||||
]);
|
||||
insta::assert_snapshot!(output, @r"
|
||||
From 993219c0b219b5eeac6303b5cb2bf943ea719672 Mon Sep 17 00:00:00 2001
|
||||
From: Test User <test.user@example.com>
|
||||
Date: Sat, 3 Feb 2001 04:05:08 +0700
|
||||
Subject: [PATCH] some change
|
||||
|
||||
multiline desc
|
||||
second line
|
||||
|
||||
with blanks
|
||||
---
|
||||
file1 | 1 -
|
||||
file2 | 2 +-
|
||||
file3 | 1 +
|
||||
3 files changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
[EOF]
|
||||
");
|
||||
}
|
||||
|
@ -766,6 +766,7 @@ fn test_template_alias() {
|
||||
commit_summary_separator
|
||||
description_placeholder
|
||||
email_placeholder
|
||||
git_format_patch_email_headers
|
||||
name_placeholder
|
||||
[EOF]
|
||||
");
|
||||
|
@ -361,6 +361,7 @@ fn test_evolog_with_no_template() {
|
||||
- commit_summary_separator
|
||||
- description_placeholder
|
||||
- email_placeholder
|
||||
- git_format_patch_email_headers
|
||||
- name_placeholder
|
||||
[EOF]
|
||||
[exit status: 2]
|
||||
|
@ -63,6 +63,7 @@ fn test_log_with_no_template() {
|
||||
- commit_summary_separator
|
||||
- description_placeholder
|
||||
- email_placeholder
|
||||
- git_format_patch_email_headers
|
||||
- name_placeholder
|
||||
[EOF]
|
||||
[exit status: 2]
|
||||
|
@ -182,6 +182,7 @@ fn test_op_log_with_no_template() {
|
||||
- commit_summary_separator
|
||||
- description_placeholder
|
||||
- email_placeholder
|
||||
- git_format_patch_email_headers
|
||||
- name_placeholder
|
||||
[EOF]
|
||||
[exit status: 2]
|
||||
|
@ -288,6 +288,7 @@ fn test_show_with_no_template() {
|
||||
- commit_summary_separator
|
||||
- description_placeholder
|
||||
- email_placeholder
|
||||
- git_format_patch_email_headers
|
||||
- name_placeholder
|
||||
[EOF]
|
||||
[exit status: 2]
|
||||
|
@ -29,6 +29,9 @@ run_command "jj diff -r b1"
|
||||
blank
|
||||
run_command "jj diff -r b3"
|
||||
|
||||
comment "We can generate a 'git format-patch' compatible diff"
|
||||
run_command "jj show --git --template git_format_patch_email_headers"
|
||||
|
||||
comment "The repo is backed by the actual Git repo:"
|
||||
run_command "git --git-dir=.jj/repo/store/git log --graph --all --decorate --oneline"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user