-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Problem
:CodeDiff file <revision> does not work if the file has been copied in the past (maybe this is also true for renames, but I'm not sure.).
When diffing the file (e.g. commands.lua), then if the hash is from before the rename it will show the whole content of the file as new.
Where it should only show the changes like this (I've hardcoded the old path just to illustrate it).
Cause
I believe the problem is here:
-- Compare revision vs working tree
vim.schedule(function()
local view = require("codediff.ui.view")
---@type SessionConfig
local session_config = {
mode = "standalone",
git_root = git_root,
original_path = relative_path,
modified_path = relative_path,
original_revision = commit_hash,
modified_revision = "WORKING",
}
view.create(session_config, filetype)
end)The modified_path may not be the same at the specified revision.
For example, looking at this project, there is a file named commands.lua.
$ git log --follow --name-status --oneline -- commands.lua
<cut>
60dbf8f feat: add make format target for Lua auto-formatting
M lua/codediff/commands.lua
62fca8c refactor(dir): improve directory diff integration
M lua/codediff/commands.lua
5f46712 feat: add directory diff
M lua/codediff/commands.lua
f9426e0 refactor: rename vscode-diff to codediff with backward compatibility
C096 lua/vscode-diff/commands.lua lua/codediff/commands.lua
d55e6d2 refactor: rename render/ to ui/ and organize core utilities
M lua/vscode-diff/commands.lua
eb03790 chore: merge main features into next
M lua/vscode-diff/commands.lua
3cd89b1 feat: dynamic git revision completion for :CodeDiff command
M lua/vscode-diff/commands.lua
98e2d0c feat: add synchronous CodeDiff merge command for git mergetool
M lua/vscode-diff/commands.lua
The file has been copied from the lua/vscode-diff/commands.lua and there is no way to name the old path when diffing.
Git has mechanisms to do it by prefixing the path with a commit hash:
git diff 60dbf8f:lua/codediff/commands.lua 98e2d0c:lua/vscode-diff/commands.lua
but this wont work with codediff.