fix(jj): detect renamed files correctly - #306
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect rename/copy detection in the Jujutsu (jj) adapter. Previously, tracked_files ran jj diff --summary and parsed lines like R common/{a.txt => b.txt} with a regex. jj's --summary renders renames/copies through display_diff_path(), which factors out common path prefixes/suffixes into a lossy, unparseable form (stray braces, and genuinely ambiguous output when paths contain {, }, or =>). The PR replaces --summary with a jj diff -T <template> invocation that emits the status char, target path, and (for renames/copies) the source path as separate \x1f-delimited fields, then parses each line deterministically. This aligns with the existing FH_TEMPLATE approach already used for jj log.
I verified against jj's official template docs and CHANGELOG that every method used (TreeDiffEntry.status_char(), .path(), .status(), .source().path()) is valid and available by jj 0.37.0, which is below the project's documented minimum of jj ≥ 0.38.0 — so there is no version-compatibility regression. This is the only jj diff --summary call site.
Changes:
- Add
TRACKED_FILES_TEMPLATEandparse_tracked_files_line, and switchtracked_filesfrom--summaryto-T <template>parsing. - Simplify the file-collection loop to consume the new parser's
status/path/oldpathreturn values. - Add unit tests for
parse_tracked_files_lineand integration tests covering renames with common suffixes, literal{/}, and=>in names.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lua/diffview/vcs/adapters/jj/init.lua |
Adds the diff template + line parser, rewires tracked_files, and exports both via _test. |
lua/diffview/tests/functional/jj_adapter_spec.lua |
Adds unit tests for the parser and integration tests for tricky rename path shapes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| M._test = { | ||
| structure_fh_data = structure_fh_data, | ||
| FH_TEMPLATE = FH_TEMPLATE, | ||
| TRACKED_FILES_TEMPLATE = TRACKED_FILES_TEMPLATE, |
There was a problem hiding this comment.
I think this isn't necessary to export?
There was a problem hiding this comment.
Oh, you're right. I didn't double check. I believe the same applies to FH_TEMPLATE, as it isn't used anywhere either. So I guess I can remove both, right?
d65100e to
953e3b7
Compare
I've been trying out
diffview+withjjand I've run into an issue with renamed files where the apparently default format forjj diff --summaryfor renamed files factors out common path components as follows:R common/{a.txt => b.txt}. The present parse withlocal from_path, to_path = path:match("^(.-)%s+=>%s+(.-)$")doesn't handle this format correctly which results in renamed file paths containing stray braces and being in general broken.This PR fixes this issue by using a template for
jj diffinstead of the--summaryoption, that always emits the new and old paths separately. The implementation follows the pattern of other templates (e.g., the FH_TEMPLATE) and covers the functionality with tests.