Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ vim.api.nvim_set_keymap(
)
```


#### _Keymaps_

- `<CR>` opens a diff for the current file with the selected commit
Expand Down Expand Up @@ -149,26 +148,53 @@ With Lazy
"aaronhallaert/advanced-git-search.nvim",
config = function()
require("telescope").load_extension("advanced_git_search")

require("telescope").setup{
-- move this to the place where you call the telescope setup function
extensions = {
advanced_git_search = {
-- fugitive or diffview
diff_plugin = "fugitive",
}
}
}
end,
dependencies = {
"nvim-telescope/telescope.nvim",
-- to show diff splits and open commits in browser
"tpope/vim-fugitive",
-- OPTIONAL: to replace the diff from fugitive with diffview.nvim
-- (fugitive is still needed to open in browser)
-- "sindrets/diffview.nvim",
},
}
```

With Packer

```lua
use({
"aaronhallaert/advanced-git-search.nvim",
config = function()
require("telescope").load_extension("advanced_git_search")

require("telescope").setup{
-- move this to the place where you call the telescope setup function
extensions = {
advanced_git_search = {
-- fugitive or diffview
diff_plugin = "fugitive",
}
}
}
end,
requires = {
"nvim-telescope/telescope.nvim",
-- to show diff splits and open commits in browser
"tpope/vim-fugitive",
-- OPTIONAL: to replace the diff from fugitive with diffview.nvim
-- (fugitive is still needed to open in browser)
-- "sindrets/diffview.nvim",
},
})
```
Expand All @@ -177,4 +203,5 @@ With Packer

- git
- vim-fugitive
- sindrets/diffview.nvim
- telescope.nvim
17 changes: 15 additions & 2 deletions lua/advanced_git_search/git_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local file = require("advanced_git_search.utils.file")
local utils = require("advanced_git_search.utils")
local finders = require("telescope.finders")
local previewers = require("telescope.previewers")
local config = require("advanced_git_search.utils.config")

local last_prompt = nil
local M = {}
Expand Down Expand Up @@ -202,10 +203,22 @@ M.open_diff_view = function(
commit, --[[optional]]
file_name
)
local diff_plugin = config.diff_plugin()

if file_name ~= nil and file_name ~= "" then
vim.api.nvim_command(":Gvdiffsplit " .. commit .. ":" .. file_name)
if diff_plugin == "diffview" then
vim.api.nvim_command(
":DiffviewOpen " .. commit .. " -- " .. file_name
)
elseif diff_plugin == "fugitive" then
vim.api.nvim_command(":Gvdiffsplit " .. commit .. ":" .. file_name)
end
else
vim.api.nvim_command(":Gvdiffsplit " .. commit)
if diff_plugin == "diffview" then
vim.api.nvim_command(":DiffviewOpen " .. commit)
elseif diff_plugin == "fugitive" then
vim.api.nvim_command(":Gvdiffsplit " .. commit)
end
end
end

Expand Down
48 changes: 48 additions & 0 deletions lua/advanced_git_search/utils/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
local M = {}

local config = {}

M.setup = function(ext_config)
ext_config = ext_config or {}

ext_config.diff_plugin = ext_config.diff_plugin or "fugitive"

config = ext_config
end

M.get_config = function()
return config
end

M.diff_plugin = function()
local diff_plugin = config["diff_plugin"]

if diff_plugin == "fugitive" and vim.fn.exists(":Gvdiffsplit") == 0 then
vim.notify(
"fugitive configured but git-fugitive is not installed",
vim.log.levels.ERROR,
{ title = "Advanced Git Search" }
)
return nil
elseif
diff_plugin == "diffview" and vim.fn.exists(":DiffviewOpen") == 0
then
vim.notify(
"diffview configured but diffview.nvim is not installed",
vim.log.levels.ERROR,
{ title = "Advanced Git Search" }
)
return nil
elseif diff_plugin == nil then
vim.notify(
"No diff plugin configured",
vim.log.levels.ERROR,
{ title = "Advanced Git Search" }
)
return nil
end

return diff_plugin
end

return M
4 changes: 4 additions & 0 deletions lua/telescope/_extensions/advanced_git_search.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
local func = require("advanced_git_search")
local config = require("advanced_git_search.utils.config")

return require("telescope").register_extension({
setup = function(ext_config, _)
config.setup(ext_config)
end,
exports = {
checkout_reflog = func.checkout_reflog,
diff_branch_file = func.diff_branch_file,
Expand Down