Skip to content
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

bug: viewing diff with diffview.nvim not working #304

Closed
3 tasks done
kuntau opened this issue Jan 4, 2023 · 9 comments · Fixed by #312 or #352
Closed
3 tasks done

bug: viewing diff with diffview.nvim not working #304

kuntau opened this issue Jan 4, 2023 · 9 comments · Fixed by #312 or #352
Labels
bug Something isn't working

Comments

@kuntau
Copy link

kuntau commented Jan 4, 2023

Did you check docs and existing issues?

  • I have read all the lazy docs
  • I have searched the existing issues of lazy
  • I have searched the exsiting issues of the plugin I have a problem with

Neovim version (nvim -v)

NVIM v0.9.0-dev-cb9d68fe

Operating system/version

MacOS 10.15.7

Describe the bug

On first start diffview open with empty file. Subsequent open will give error

[Diffview.nvim] Not a repo (or any parent), or no supported VCS adapter!

Steps To Reproduce

  1. Open lazy window
  2. Update/log
  3. Press d on any git hash

Expected Behavior

Actual diff is shown.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  "sindrets/diffview.nvim",
  "nvim-lua/plenary.nvim",
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
  checker = {
	-- automatically check for plugin updates
	enabled = false,
	concurrency = 1, ---@type number? set to 1 to check for updates very slowly
	notify = true, -- get a notification when new updates are found
	frequency = 3600*2, -- check for updates every hour
  },
  diff = { cmd = "diffview.nvim" },
})

vim.cmd.colorscheme("tokyonight")
vim.g.mapleader = [[ ]]
vim.keymap.set('n','gol','<cmd>Lazy<cr>')
-- add anything else here
@kuntau kuntau added the bug Something isn't working label Jan 4, 2023
@folke folke closed this as completed in e61b334 Jan 4, 2023
@kuntau
Copy link
Author

kuntau commented Jan 5, 2023

Thank you for the fix @folke, but diffview still not fully working.

After Lazy check and you get updates. Press d on hash did show diffview correctly.

But if you go to Log view and press d on hash, diffview still give empty window.

Edit: Weird, sometimes it work and sometimes not...

@folke
Copy link
Owner

folke commented Jan 5, 2023

You need to press <d> on the actual commit hash. If you press <d> anywhere else, an updated diff is shown. If there's no updates, that woyld be empty. Is that the issue?

@kuntau
Copy link
Author

kuntau commented Jan 5, 2023

I'll to screen record... Yes, I press d on actual commit hash.

If I repeat the same action with other diff value it works just fine. I've tried git, terminal_git all show the actual diff

@kuntau
Copy link
Author

kuntau commented Jan 5, 2023

Asciinema recording

549655

@folke folke reopened this Jan 5, 2023
@folke
Copy link
Owner

folke commented Jan 6, 2023

I can't reproduce this. Do be aware that you need internet connection and need to wait a bit for the diff to load, since lazy uses partial commits. When showing a single commit for which git does not yet have the blobs, they will be downloaded on demand.

@folke folke closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2023
@sindrets
Copy link

sindrets commented Jan 8, 2023

if diff.commit then
args = ("-C=%s"):format(plugin.dir) .. " " .. diff.commit
else

Diffview always treats git revs the same way as git-diff, so the equivalent to doing git show <commit>, would be :DiffviewOpen <commit>^!.

The notation <rev>^! explicitly describes the range of a single commit. Using non-range revs have different meanings for different git commands. In this case, git diff <commit> will compare the commit against the working tree. Whereas git diff <commit>^! will show only the changes introduced in the given commit. Which is what I assume was the intention here?

@folke
Copy link
Owner

folke commented Jan 9, 2023

@sindrets updated, thanks!

@kuntau
Copy link
Author

kuntau commented Jan 9, 2023

Diffview always treats git revs the same way as git-diff, so the equivalent to doing git show <commit>, would be :DiffviewOpen <commit>^!.

Thank you. Changing those line as suggested fix the issue

diff --git a/lua/lazy/view/diff.lua b/lua/lazy/view/diff.lua
index 24955b8..f4fe5af 100644
--- a/lua/lazy/view/diff.lua
+++ b/lua/lazy/view/diff.lua
@@ -25,7 +25,7 @@ M.handlers = {
   ["diffview.nvim"] = function(plugin, diff)
     local args
     if diff.commit then
-      args = ("-C=%s"):format(plugin.dir) .. " " .. diff.commit
+      args = ("-C=%s"):format(plugin.dir) .. " " .. diff.commit .. "^!"
     else
       args = ("-C=%s"):format(plugin.dir) .. " " .. diff.from .. ".." .. diff.to
     end

@kuntau
Copy link
Author

kuntau commented Jan 9, 2023

Ops... @folke is too fast 🥂

kuntau added a commit to kuntau/dotfiles that referenced this issue Jan 9, 2023
kuntau added a commit to kuntau/dotfiles that referenced this issue Jul 12, 2024
kuntau added a commit to kuntau/dotfiles that referenced this issue Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants