-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
annotate: make AnnotationLine template type
Allows: * self.commit() * self.line_number() * self.first_line_in_hunk() Certain pagers (like `delta`), when used for `git blame`, only show the commit information for the first line in a hunk. This would be a nice addition to `jj file annotate`. `jj file annotate` already uses a template to control the rendering of commit information --- `templates.annotate_commit_summary`. Instead of a custom CLI flag, the tools necessary to do this should be available in the template language. If `1 % 2` or `1.is_even()` was available in the template language, this would also allow alternating colors (using `raw_escape_sequence`). Example: ```toml [templates] # only show commit info for the first line of each hunk annotate_commit_summary = ''' if(first_line_in_hunk, show_commit_info(commit), pad_end(20, " "), ) ''' ```
- Loading branch information
1 parent
6ec337e
commit 3bc111e
Showing
7 changed files
with
189 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,3 +149,57 @@ fn test_annotate_merge_one_sided_conflict_resolution() { | |
zsuskuln test.use 2001-02-03 08:05:11 2: new text from new commit 1 | ||
"); | ||
} | ||
|
||
#[test] | ||
fn test_annotate_with_template() { | ||
let test_env = TestEnvironment::default(); | ||
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); | ||
let repo_path = test_env.env_root().join("repo"); | ||
|
||
std::fs::write(repo_path.join("file.txt"), "line1\n").unwrap(); | ||
test_env.jj_cmd_ok(&repo_path, &["commit", "-m=initial"]); | ||
|
||
append_to_file( | ||
&repo_path.join("file.txt"), | ||
"new text from new commit 1\nthat splits into multiple lines", | ||
); | ||
test_env.jj_cmd_ok(&repo_path, &["commit", "-m=commit1"]); | ||
|
||
append_to_file( | ||
&repo_path.join("file.txt"), | ||
"new text from new commit 2\nalso continuing on a second line\nand a third!", | ||
); | ||
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=commit2"]); | ||
|
||
let template = indoc::indoc! {r#" | ||
if(first_line_in_hunk, "\n" ++ separate("\n", | ||
commit.change_id().shortest(8) | ||
++ " " | ||
++ commit.description().first_line(), | ||
commit_timestamp(commit).local().format('%Y-%m-%d %H:%M:%S') | ||
++ " " | ||
++ commit.author(), | ||
) ++ "\n") ++ pad_start(4, line_number) ++ ": " | ||
"#}; | ||
|
||
let stdout = test_env.jj_cmd_success( | ||
&repo_path, | ||
&["file", "annotate", "file.txt", "-T", template], | ||
); | ||
insta::assert_snapshot!(stdout, @r#" | ||
qpvuntsm initial | ||
2001-02-03 08:05:08 Test User <[email protected]> | ||
1: line1 | ||
rlvkpnrz commit1 | ||
2001-02-03 08:05:09 Test User <[email protected]> | ||
2: new text from new commit 1 | ||
3: that splits into multiple lines | ||
kkmpptxz commit2 | ||
2001-02-03 08:05:10 Test User <[email protected]> | ||
4: new text from new commit 2 | ||
5: also continuing on a second line | ||
6: and a third! | ||
"#); | ||
} |
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