Skip to content

fix(jj): detect renamed files correctly - #306

Open
jakubbortlik wants to merge 1 commit into
dlyongemallo:mainfrom
jakubbortlik:fix/jj-renamed-files
Open

fix(jj): detect renamed files correctly#306
jakubbortlik wants to merge 1 commit into
dlyongemallo:mainfrom
jakubbortlik:fix/jj-renamed-files

Conversation

@jakubbortlik

Copy link
Copy Markdown

I've been trying out diffview+ with jj and I've run into an issue with renamed files where the apparently default format for jj diff --summary for renamed files factors out common path components as follows: R common/{a.txt => b.txt}. The present parse with local 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 diff instead of the --summary option, 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_TEMPLATE and parse_tracked_files_line, and switch tracked_files from --summary to -T <template> parsing.
  • Simplify the file-collection loop to consume the new parser's status/path/oldpath return values.
  • Add unit tests for parse_tracked_files_line and 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.

Comment thread lua/diffview/vcs/adapters/jj/init.lua Outdated
M._test = {
structure_fh_data = structure_fh_data,
FH_TEMPLATE = FH_TEMPLATE,
TRACKED_FILES_TEMPLATE = TRACKED_FILES_TEMPLATE,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't necessary to export?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants