diff options
| author | Cyan <cyan.joeng@outlook.com> | 2022-12-28 12:43:35 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-28 15:43:35 +0300 |
| commit | 01d92285ef4402b188fa583d57f5d1a18c889d22 (patch) | |
| tree | 78fad00ad7895336497d27b36b79b160c0e5cb4d /lua/telescope | |
| parent | d7d3ea901580a7ef43aa9a2870ff36673eeadd6c (diff) | |
feat(git): git_commits shows the current branch graph (#2288)
Co-authored-by: Cyan Joeng <cyan.joeng@gmail.com>
Diffstat (limited to 'lua/telescope')
| -rw-r--r-- | lua/telescope/builtin/__git.lua | 5 | ||||
| -rw-r--r-- | lua/telescope/make_entry.lua | 18 |
2 files changed, 16 insertions, 7 deletions
diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua index 1b9d0fa..2228180 100644 --- a/lua/telescope/builtin/__git.lua +++ b/lua/telescope/builtin/__git.lua @@ -56,7 +56,7 @@ end git.commits = function(opts) opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_commits(opts)) - local git_command = vim.F.if_nil(opts.git_command, { "git", "log", "--pretty=oneline", "--abbrev-commit", "--", "." }) + local git_command = vim.F.if_nil(opts.git_command, { "git", "log", "--graph", "--oneline", "--decorate", "--", "." }) pickers .new(opts, { @@ -115,8 +115,7 @@ git.bcommits = function(opts) opts.current_line = (opts.current_file == nil) and get_current_buf_line(opts.winnr) or nil opts.current_file = vim.F.if_nil(opts.current_file, vim.api.nvim_buf_get_name(opts.bufnr)) opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_commits(opts)) - local git_command = - vim.F.if_nil(opts.git_command, { "git", "log", "--pretty=oneline", "--abbrev-commit", "--follow" }) + local git_command = vim.F.if_nil(opts.git_command, { "git", "log", "--graph", "--oneline", "--decorate", "--follow" }) pickers .new(opts, { diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 3843e5d..2532997 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -431,17 +431,27 @@ function make_entry.gen_from_git_commits(opts) return nil end - local sha, msg = string.match(entry, "([^ ]+) (.+)") + local marker, sha, msg = string.match(entry, "([*\\/| ]+) +([0-9a-f]*) +(.*)") + + if not sha then + marker = entry + sha = "" + msg = "" + end if not msg then - sha = entry msg = "<empty commit message>" end + marker, _ = string.gsub(marker, "\\", "+") + marker, _ = string.gsub(marker, "/", "-") + marker, _ = string.gsub(marker, "+", "/") + marker, _ = string.gsub(marker, "-", "\\") + return make_entry.set_default_entry_mt({ value = sha, - ordinal = sha .. " " .. msg, - msg = msg, + ordinal = marker .. " " .. sha .. " " .. msg, + msg = marker .. " " .. msg, display = make_display, current_file = opts.current_file, }, opts) |
