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
4 changes: 2 additions & 2 deletions lua/advanced_git_search/actions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ M.open_diff_view = function(commit, file_name)
if file_name ~= nil and file_name ~= "" then
if diff_plugin == "diffview" then
vim.api.nvim_command(
":DiffviewOpen " .. commit .. " -- " .. file_name
":DiffviewOpen -uno " .. commit .. " -- " .. file_name
)
elseif diff_plugin == "fugitive" then
vim.api.nvim_command(":Gvdiffsplit " .. commit .. ":" .. file_name)
end
else
if diff_plugin == "diffview" then
vim.api.nvim_command(":DiffviewOpen " .. commit)
vim.api.nvim_command(":DiffviewOpen -uno " .. commit)
elseif diff_plugin == "fugitive" then
vim.api.nvim_command(":Gvdiffsplit " .. commit)
end
Expand Down
22 changes: 3 additions & 19 deletions lua/advanced_git_search/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ local M = {}

--- Opens a Telescope window with all files changed on the current branch
--- Only committed changes will be displayed
---
--- <CR> to open the file
M.changed_on_branch = function()
pickers
.new({
Expand All @@ -30,8 +28,6 @@ M.changed_on_branch = function()
end

--- Opens a Telescope window with a list of local branches
---
--- <CR> opens a diff for the current file with the selected branch
M.diff_branch_file = function()
-- local previewers = require('telescope.previewers')
local current_branch = git_utils.current_branch()
Expand All @@ -54,9 +50,6 @@ end

--- Opens a Telescope window with a list of previous commit logs
--- with respect to selected lines
---
--- <CR> opens a diff for the current file with the selected commit
--- <C-o> opens a the selected commit in the browser
M.diff_commit_line = function()
local bufnr = vim.fn.bufnr()
local s_start = vim.fn.getpos("'<")[2]
Expand All @@ -75,6 +68,7 @@ M.diff_commit_line = function()
ags_mappings.open_diff_view_current_file_selected_commit(map)
ags_mappings.open_selected_commit_in_browser(map)
ags_mappings.copy_commit_hash_to_clipboard(map)
ags_mappings.show_entire_commit(map)
return true
end,
})
Expand All @@ -84,9 +78,6 @@ end
--- Opens a Telescope window with a list of previous commits.
--- Query is used to filter the results based on the
--- content of the commit (added or removed text).
---
--- <CR> opens a diff for the current file with the selected commit
--- <C-o> opens a the selected commit in the browser
M.search_log_content = function()
-- git log -L741,751:'app/models/patients/patient.rb' \
-- --format='%C(auto)%h \t %as \t %C(green)%an _ %Creset %s'
Expand All @@ -100,16 +91,14 @@ M.search_log_content = function()
ags_mappings.open_diff_view_current_file_selected_commit(map)
ags_mappings.open_selected_commit_in_browser(map)
ags_mappings.copy_commit_hash_to_clipboard(map)
ags_mappings.show_entire_commit(map)
return true
end,
})
:find()
end

--- Same as `search_log_content` but with respect to the current file
---
--- <CR> opens a diff for the current file with the selected commit
--- <C-o> opens a the selected commit in the browser
M.search_log_content_file = function()
-- local file_name = vim.fn.expand("%")
-- local relative_file_name = vim.fn.expand("%:~:.")
Expand All @@ -129,6 +118,7 @@ M.search_log_content_file = function()
ags_mappings.open_diff_view_current_file_selected_commit(map)
ags_mappings.open_selected_commit_in_browser(map)
ags_mappings.copy_commit_hash_to_clipboard(map)
ags_mappings.show_entire_commit(map)

return true
end,
Expand All @@ -137,10 +127,6 @@ M.search_log_content_file = function()
end

-- Opens a Telescope window with a list of git commits which changed the current file (renames included)
--
-- <CR> Opens a diff of the current file with the selected commit
-- <C-e> Opens an entire git diff of the selected commit
-- <C-o> Open the selected commit in the browser
M.diff_commit_file = function()
local bufnr = vim.fn.bufnr()
pickers
Expand All @@ -163,8 +149,6 @@ M.diff_commit_file = function()
end

--- Opens a Telescope window with all reflog entries
---
--- <CR> checkout on the reflog entry
M.checkout_reflog = function()
pickers
.new({
Expand Down
23 changes: 9 additions & 14 deletions lua/advanced_git_search/mappings/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local ags_actions = require("advanced_git_search.actions")
local action_state = require("telescope.actions.state")
local file = require("advanced_git_search.utils.file")
local git_utils = require("advanced_git_search.utils.git")
local config = require("advanced_git_search.utils.config")

-- Map a key to both insert and normal modes
local function omnimap(map_func, key, handler)
Expand Down Expand Up @@ -66,20 +67,14 @@ local open_entire_commit = function(prompt_bufnr)
local selection = action_state.get_selected_entry()
local commit_hash = selection.opts.commit_hash

local command = {
"git",
"diff",
string.format("%s~", commit_hash),
commit_hash,
"\n",
}

vim.api.nvim_command("split new") -- split a new window
vim.api.nvim_win_set_height(0, 30) -- set the window height
local buf_handle = vim.api.nvim_win_get_buf(0) -- get the buffer handler
local jobID = vim.api.nvim_call_function("termopen", { "$SHELL" })
vim.api.nvim_buf_set_option(buf_handle, "modifiable", true)
vim.api.nvim_chan_send(jobID, table.concat(command, " "))
local diff_plugin = config.diff_plugin()
if diff_plugin == "diffview" then
vim.api.nvim_command(
":DiffviewOpen -uno " .. commit_hash .. "~.." .. commit_hash
)
elseif diff_plugin == "fugitive" then
vim.api.nvim_command(":Gedit " .. commit_hash)
end
end

--- open entire commit diff with <C-e>
Expand Down