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] Providing git rev shows changes beyond revision #514

Open
TJ-Adams opened this issue Jun 23, 2024 · 2 comments
Open

[Bug] Providing git rev shows changes beyond revision #514

TJ-Adams opened this issue Jun 23, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@TJ-Adams
Copy link

Description

From the README.

You can also provide any valid git rev to view only changes for that rev.

From reading this, providing a git revision such as a SHA1 should only show changes provided by that change and that change only. However I'm seeing that it shows the difference against the HEAD, which if you go far back makes the diff seem huge.

I did a quick initial triage and it seems to be because in the function diffview_open, the right parameter is always set to LOCAL when only the SHA1 is given.

Expected behavior

No response

Actual behavior

Providing the valid git rev, SHA1 in this case, should show only the changes that occurred for that revision.

Steps to reproduce

  1. Clone down a git repo of your choosing
  2. Pick any commit that isn't the most recent commit (preferably an older one)
  3. run nvim -u mini.lua with the provided minimal config below
  4. Run DiffviewOpen
  5. Compare the diffview with what git said was changed in the commit.
  6. Confirm that they're different

Health check

Output of :checkhealth diffview
diffview: require("diffview.health").check()

Checking plugin dependencies ~
- OK nvim-web-devicons installed.

Checking VCS tools ~
- The plugin requires at least one of the supported VCS tools to be valid.
- OK Git found.
- OK Git is up-to-date. (2.39.3)
- WARNING Configured `hg_cmd` is not executable: 'hg'

Log info

Relevant info from :DiffviewLog
############################
### PUT LOG CONTENT HERE ###
############################

Neovim version

NVIM v0.10.0-dev-2849+g4946489e2
Build type: RelWithDebInfo
LuaJIT 2.1.1710088188
Run "nvim -V1 -v" for more info

Operating system and version

Darwin 23.5.0 arm64

Minimal config

-- #######################################
-- ### USAGE: nvim --clean -u mini.lua ###
-- #######################################

local root = vim.fn.stdpath("run") .. "/nvim/diffview.nvim"
local plugin_dir = root .. "/plugins"
vim.fn.mkdir(plugin_dir, "p")

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

local plugins = {
  { "nvim-web-devicons", url = "https://github.com/nvim-tree/nvim-web-devicons.git" },
  { "diffview.nvim", url = "https://github.com/sindrets/diffview.nvim.git" },
  -- ##################################################################
  -- ### ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
  -- ##################################################################
}

for _, spec in ipairs(plugins) do
  local install_path = plugin_dir .. "/" .. spec[1]
  if vim.fn.isdirectory(install_path) ~= 1 then
    if spec.url then
      print(string.format("Installing '%s'...", spec[1]))
      vim.fn.system({ "git", "clone", "--depth=1", spec.url, install_path })
    end
  end
  vim.opt.runtimepath:append(spec.path or install_path)
end

require("diffview").setup({
  -- ##############################################################################
  -- ### ADD DIFFVIEW.NVIM CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE ###
  -- ##############################################################################
})

vim.opt.termguicolors = true
vim.cmd("colorscheme " .. (vim.fn.has("nvim-0.8") == 1 and "habamax" or "slate"))

-- ############################################################################
-- ### ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
-- ############################################################################

print("Ready!")
@TJ-Adams TJ-Adams added the bug Something isn't working label Jun 23, 2024
@TJ-Adams
Copy link
Author

Easy workaround in the meantime is to just use command DiffviewOpen <SHA1>~1..<SHA1>. Thank you for the plugin! I think it's pretty great.

@tmillr
Copy link

tmillr commented Jun 24, 2024

I find this a little annoying as well. commit^! or <SHA1>~1..<SHA1> just don't feel very ergonomic, and the former isn't very common imo. I'm guessing they are replicating the behavior of git diff as opposed to git show in this case. With that said, this probably isn't a bug, but the docs could be clarified.

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

No branches or pull requests

2 participants