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

Add option to open commit diff in a buffer from Commits or BCommits, a la FZF #860

Open
VVKot opened this issue May 25, 2021 · 5 comments
Open
Labels
enhancement Enhancement to performance, inner workings or existent features

Comments

@VVKot
Copy link
Contributor

VVKot commented May 25, 2021

Is your feature request related to a problem? Please describe.
Currently action mapped in commits picker is checkout. This is quite often not what I want and I would rather have an option to see commit's diff in a buffer. Diff in the preview would somewhat solve the problem. It still does not give all the power and flexibility of a separate buffer though.

Describe the solution you'd like
There is an option to override action on from commits/bcommits, so that instead of checking out this commit I get a buffer with this commit's diff.

Describe alternatives you've considered
Continuing to use fzf.vim for this.

Additional context
There is #528 which I assume will unblock this?

@VVKot VVKot added the enhancement Enhancement to performance, inner workings or existent features label May 25, 2021
@Conni2461
Copy link
Member

#528 implements open diff for bcommits when doing <c-v>, <c-x> or <c-t> not commits tho

@VVKot
Copy link
Contributor Author

VVKot commented Jun 14, 2021

I guess what I really want is integration with fugitive (because that's what fzf.vim) does. I imagine that would require a bit more thought.

@VVKot
Copy link
Contributor Author

VVKot commented Aug 10, 2021

For future readers - what I ended up using instead: https://github.com/junegunn/gv.vim

@fdschmidt93
Copy link
Member

fdschmidt93 commented Aug 10, 2021

With diffview.nvim you can easily write actions that I think achieve what you were looking for as suggested in this thread

local action_state = require "telescope.actions.state"
local ts_utils = require "telescope.utils"

-- in your setup
  pickers = {
    git_commits = {
      mappings = {
        i = {
          ["your mapping here"] = function(prompt_bufnr)
            actions.close(prompt_bufnr)
            local value = action_state.get_selected_entry().value
            -- changes from commit against current index
            local cmd = "DiffviewOpen " .. value
            -- for changes from one commit to the previous one
            local cmd = "DiffviewOpen " .. value .. "~1.." .. value
            --- feature branch against branch of your choice
            local rev = ts_utils.get_os_command_output({ "git", "rev-parse", "branch-name-here" }, vim.loop.cwd())[1]
            cmd = "DiffviewOpen " .. rev .. " " .. value)
            vim.cmd(cmd)
          end,
        }
      }
    }

@rx2130
Copy link

rx2130 commented Sep 27, 2021

I guess what I really want is integration with fugitive (because that's what fzf.vim) does. I imagine that would require a bit more thought.

+1. I also much prefer fzf :Commits/:BCommits behavior that open selected commit in fugitive instead of telescope checkout to that commit. I suppose most often people want to read commit rather than checkout?

FWIW I have being using the following code to open in fugitive.

actions.git_fugitive = function(prompt_bufnr)
  local cwd = action_state.get_current_picker(prompt_bufnr).cwd
  local selection = action_state.get_selected_entry()
  actions.close(prompt_bufnr)

  sha = selection.value
  vim.cmd("execute 'vsplit' FugitiveFind(luaeval('sha'))")
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to performance, inner workings or existent features
Projects
None yet
Development

No branches or pull requests

4 participants