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
126 changes: 106 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
# Telescope Advanced Git Search
# Advanced Git Search

An advanced git search extension for `Telescope` and `fzf-lua`.

Search your git history by commit message, content and author in Neovim

## 🖥️ Usage

[![Demo](https://img.youtube.com/vi/bO0uYLlHtYo/0.jpg)](https://www.youtube.com/watch?v=bO0uYLlHtYo)
- [Demo](https://www.youtube.com/watch?v=bO0uYLlHtYo)

### 📖 Open a picker

#### 🔭 Telescope

```vim
:Telescope advanced_git_search {function_name}
```

#### or in lua
> or in lua

```lua
require('telescope').extensions.advanced_git_search.{function_name}()
```

#### or through another Telescope picker
> or through another Telescope picker

execute `:AdvancedGitSearch`, choose your picker and press `<CR>`

#### 🧎 fzf-lua

```lua
require('advanced-git-search.fzf').{function_name}()
```

> or through another picker

execute `:AdvancedGitSearch`, choose your picker and press `<CR>`

### 🔎 Enter a query

Your usual telescope experience. See the individual commands for the grep behaviour.
Your usual search experience. See the individual commands for the grep behaviour.

### ✏️ Further search on commit author with `@`

Expand All @@ -33,7 +49,7 @@ the author name.

### 1. search_log_content -- Search in repo log content

Opens a Telescope window with a list of all previous commit.
Opens a window with a list of all previous commit.

_Grep behaviour_: filter on added, updated or removed code (log content: `-G` option in git).

Expand All @@ -46,7 +62,7 @@ _Grep behaviour_: filter on added, updated or removed code (log content: `-G` op

### 2. search_log_content_file -- Search in file log content

Opens a Telescope window with a list of git commits that changed the
Opens a window with a list of git commits that changed the
current file (renames included).

_Grep behaviour_: filter on added, updated or removed code (log content: `-G` option in git).
Expand All @@ -60,7 +76,7 @@ _Grep behaviour_: filter on added, updated or removed code (log content: `-G` op

### 3. diff_commit_file -- Diff current file with commit

Opens a Telescope window with a list of git commits that changed the
Opens a window with a list of git commits that changed the
current file (renames included).

_Grep behaviour_: filter on commit message.
Expand All @@ -74,19 +90,18 @@ _Grep behaviour_: filter on commit message.

### 4. diff_commit_line -- Diff current file with selected line history

Opens a Telescope window with a list of previous commit logs with respect to
Opens a window with a list of previous commit logs with respect to
selected lines

_Grep behaviour_: filter on commit message.

#### How to use

_The following only applies when you use one of the commands below._

```vim
:Telescope advanced_git_search diff_commit_line
:lua require('telescope').extensions.advanced_git_search.diff_commit_line()
```
> _This workaround only applies when you use the following command. (Telescope)_
>
> ```vim
> :Telescope advanced_git_search diff_commit_line
> ```

First you have to select the lines in visual mode, then go back to normal
mode and execute this command.
Expand All @@ -107,7 +122,7 @@ vim.api.nvim_set_keymap(
)
```

No extra setup is needed when you use `:AdvancedGitSearch`.
> No extra setup is needed when you use `:AdvancedGitSearch`.

#### _Keymaps_

Expand All @@ -118,7 +133,7 @@ No extra setup is needed when you use `:AdvancedGitSearch`.

### 5. diff_branch_file -- Diff file with branch

Opens a Telescope window with a list of local branches
Opens a window with a list of local branches

_Grep behaviour_: filter on branch name.

Expand All @@ -128,7 +143,7 @@ _Grep behaviour_: filter on branch name.

### 6. changed_on_branch -- Changed on current branch (experimental)

Opens a Telescope window with a list of changed files on the current branch (including staged files).
Opens a window with a list of changed files on the current branch (including staged files).
The fork point of the current branch is determined with the following command:

```sh
Expand All @@ -150,7 +165,7 @@ _Grep behaviour_: filter on filename.

### 7. checkout_reflog -- Checkout from reflog

Opens a Telescope window with all reflog entries
Opens a window with all reflog entries

#### _Keymaps_

Expand All @@ -159,10 +174,12 @@ Opens a Telescope window with all reflog entries
### 8. show_custom_functions

A telescope picker for all functions above.
Enable `show_builtin_git_pickers` to additionally show Telescopes builtin git pickers.
Enable `show_builtin_git_pickers` to additionally show builtin git pickers.

## ⚙️ Installation

### Telescope

With Lazy

```lua
Expand Down Expand Up @@ -243,6 +260,75 @@ With Packer
})
```

### Fzf-lua

With Lazy

```lua
{
"aaronhallaert/advanced-git-search.nvim",
config = function()
-- optional: setup telescope before loading the extension
require("advanced-git-search.fzf").setup{
-- fugitive or diffview
diff_plugin = "fugitive",
-- customize git in previewer
-- e.g. flags such as { "--no-pager" }, or { "-c", "delta.side-by-side=false" }
git_flags = {},
-- customize git diff in previewer
-- e.g. flags such as { "--raw" }
git_diff_flags = {},
-- Show builtin git pickers when executing "show_custom_functions" or :AdvancedGitSearch
show_builtin_git_pickers = false,
}
end,
dependencies = {
"ibhagwan/fzf-lua",
-- to show diff splits and open commits in browser
"tpope/vim-fugitive",
-- to open commits in browser with fugitive
"tpope/vim-rhubarb",
-- 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()
-- optional: setup telescope before loading the extension
require("advanced-git-search.fzf").setup{
-- Fugitive or diffview
diff_plugin = "fugitive",
-- Customize git in previewer
-- e.g. flags such as { "--no-pager" }, or { "-c", "delta.side-by-side=false" }
git_flags = {},
-- Customize git diff in previewer
-- e.g. flags such as { "--raw" }
git_diff_flags = {},
-- Show builtin git pickers when executing "show_custom_functions" or :AdvancedGitSearch
show_builtin_git_pickers = false,
}
}
end,
requires = {
"ibhagwan/fzf-lua",
-- to show diff splits and open commits in browser
"tpope/vim-fugitive",
-- to open commits in browser with fugitive
"tpope/vim-rhubarb",
-- optional: to replace the diff from fugitive with diffview.nvim
-- (fugitive is still needed to open in browser)
-- "sindrets/diffview.nvim",
},
})
```

### Prerequisites

- git
Expand Down
67 changes: 67 additions & 0 deletions lua/advanced_git_search/actions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
local config = require("advanced_git_search.utils.config")

local M = {}

---General action: Open entire commit with fugitive or diffview
---@param commit_hash string
M.open_commit = function(commit_hash)
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

---General action: open diff for current file
---@param commit string commit or branch to diff with
---@param file_name string|nil file name to diff
M.open_diff_view = function(commit, file_name)
local diff_plugin = config.diff_plugin()

if file_name ~= nil and file_name ~= "" then
if diff_plugin == "diffview" then
vim.api.nvim_command(
":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 -uno " .. commit)
elseif diff_plugin == "fugitive" then
vim.api.nvim_command(":Gvdiffsplit " .. commit)
end
end
end

---General action: Copy commit hash to system clipboard
---@param commit_hash string
M.copy_to_clipboard = function(commit_hash)
vim.notify(
"Copied commit hash " .. commit_hash .. " to clipboard",
vim.log.levels.INFO,
{ title = "Advanced Git Search" }
)

vim.fn.setreg("+", commit_hash)
vim.fn.setreg("*", commit_hash)
end

---General action: Open commit in browser
---@param commit_hash string
M.open_in_browser = function(commit_hash)
vim.api.nvim_command(":GBrowse " .. commit_hash)
end

---General action: Checkout commit
---@param commit_hash string
M.checkout_commit = function(commit_hash)
vim.api.nvim_command(":!git checkout " .. commit_hash)
end

return M
28 changes: 0 additions & 28 deletions lua/advanced_git_search/actions/init.lua

This file was deleted.

Loading