-
Notifications
You must be signed in to change notification settings - Fork 832
templates: Expose conflicted files in the template language #8183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1253,6 +1253,22 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm | |
| Ok(out_property.into_dyn_wrapped()) | ||
| }, | ||
| ); | ||
| map.insert( | ||
| "conflicted_files", | ||
| |_language, _diagnostics, _build_ctx, self_property, function| { | ||
| function.expect_no_arguments()?; | ||
| let out_property = self_property.and_then(|commit| { | ||
| let tree = commit.tree(); | ||
| let entries: Vec<_> = tree | ||
| .conflicts() | ||
algmyr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .map(|(path, value)| value.map(|value| (path, value))) | ||
| .map_ok(|(path, value)| TreeEntry { path, value }) | ||
| .try_collect()?; | ||
| Ok(entries) | ||
| }); | ||
| Ok(out_property.into_dyn_wrapped()) | ||
| }, | ||
| ); | ||
| map.insert( | ||
| "root", | ||
| |language, _diagnostics, _build_ctx, self_property, function| { | ||
|
|
@@ -2446,6 +2462,15 @@ fn builtin_tree_entry_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, | |
| Ok(out_property.into_dyn_wrapped()) | ||
| }, | ||
| ); | ||
| map.insert( | ||
| "num_conflict_sides", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I slightly prefer Another idea is to add |
||
| |_language, _diagnostics, _build_ctx, self_property, function| { | ||
| function.expect_no_arguments()?; | ||
| let out_property = self_property | ||
| .and_then(|entry| Ok(i64::try_from(entry.value.simplify().num_sides())?)); | ||
| Ok(out_property.into_dyn_wrapped()) | ||
| }, | ||
| ); | ||
| map.insert( | ||
| "file_type", | ||
| |_language, _diagnostics, _build_ctx, self_property, function| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1506,6 +1506,90 @@ fn test_file_list_entries() { | |
| "); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_conflicted_files() { | ||
| let test_env = TestEnvironment::default(); | ||
| test_env.run_jj_in(".", ["git", "init", "repo"]).success(); | ||
| let work_dir = test_env.work_dir("repo"); | ||
|
|
||
| // Base commit with files. | ||
| work_dir.write_file("normal-file", "base content"); | ||
| work_dir.write_file("conflict-file1", "base content"); | ||
| work_dir.write_file("conflict-file2", "base content"); | ||
| work_dir.run_jj(["commit", "-m", "base"]).success(); | ||
|
|
||
| // Sibling branches with conflicting changes. | ||
| work_dir.write_file("conflict-file1", "left content"); | ||
| work_dir.write_file("conflict-file2", "left content"); | ||
| work_dir.run_jj(["commit", "-m", "left"]).success(); | ||
|
|
||
| work_dir.run_jj(["new", "description(base)"]).success(); | ||
| work_dir.write_file("conflict-file1", "right content"); | ||
| work_dir.write_file("conflict-file2", "right content"); | ||
| work_dir.run_jj(["commit", "-m", "right"]).success(); | ||
|
|
||
| // Merge with conflicts. | ||
| work_dir | ||
| .run_jj(["new", "description(left)", "description(right)"]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: use |
||
| .success(); | ||
|
|
||
| // Test basic conflicted_files() listing. | ||
| let template = r#"self.conflicted_files().map(|e| e.path()) ++ "\n""#; | ||
| let output = work_dir.run_jj(["log", "-r", "@", "-T", template, "--no-graph"]); | ||
| insta::assert_snapshot!(output, @r" | ||
| conflict-file1 conflict-file2 | ||
| [EOF] | ||
| "); | ||
|
|
||
| // Test that non-conflicted commit returns empty list. | ||
| let template = r#"self.conflicted_files().len() ++ "\n""#; | ||
| let output = work_dir.run_jj([ | ||
| "log", | ||
| "-r", | ||
| "description(substring:\"left\")", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: same here. |
||
| "-T", | ||
| template, | ||
| "--no-graph", | ||
| ]); | ||
| insta::assert_snapshot!(output, @r" | ||
| 0 | ||
| [EOF] | ||
| "); | ||
|
|
||
| // Metadata for conflicted_files. | ||
| let template = indoc! {r#" | ||
| self.conflicted_files().map(|e| separate(" ", | ||
| e.path(), | ||
| "conflict=" ++ e.conflict(), | ||
| "type=" ++ e.file_type(), | ||
| "sides=" ++ e.num_conflict_sides(), | ||
| )).join("\n") ++ "\n" | ||
| "#}; | ||
| let output = work_dir.run_jj(["log", "-r", "@", "-T", template, "--no-graph"]); | ||
| insta::assert_snapshot!(output, @r" | ||
| conflict-file1 conflict=true type=conflict sides=2 | ||
| conflict-file2 conflict=true type=conflict sides=2 | ||
| [EOF] | ||
| "); | ||
|
|
||
| // Metadata for all files. | ||
| let template = indoc! {r#" | ||
| self.files().map(|e| separate(" ", | ||
| e.path(), | ||
| "conflict=" ++ e.conflict(), | ||
| "type=" ++ e.file_type(), | ||
| "sides=" ++ e.num_conflict_sides(), | ||
| )).join("\n") ++ "\n" | ||
| "#}; | ||
| let output = work_dir.run_jj(["log", "-r", "@", "-T", template, "--no-graph"]); | ||
| insta::assert_snapshot!(output, @r" | ||
| conflict-file1 conflict=true type=conflict sides=2 | ||
| conflict-file2 conflict=true type=conflict sides=2 | ||
| normal-file conflict=false type=file sides=1 | ||
| [EOF] | ||
| "); | ||
| } | ||
|
|
||
| #[cfg(unix)] | ||
| #[test] | ||
| fn test_file_list_symlink() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.