mirror of
https://github.com/ThePrimeagen/harpoon
synced 2024-09-16 13:34:03 +02:00
Merge pull request #277 from pockata/faster-branch-name
Use fugitive for faster branch name resolution
This commit is contained in:
commit
3476228be2
1 changed files with 19 additions and 8 deletions
|
@ -11,14 +11,25 @@ function M.project_key()
|
|||
end
|
||||
|
||||
function M.branch_key()
|
||||
-- `git branch --show-current` requires Git v2.22.0+ so going with more
|
||||
-- widely available command
|
||||
local branch = M.get_os_command_output({
|
||||
"git",
|
||||
"rev-parse",
|
||||
"--abbrev-ref",
|
||||
"HEAD",
|
||||
})[1]
|
||||
local branch
|
||||
|
||||
-- use tpope's fugitive for faster branch name resolution if available
|
||||
if vim.fn.exists("*FugitiveHead") == 1 then
|
||||
branch = vim.fn["FugitiveHead"]()
|
||||
-- return "HEAD" for parity with `git rev-parse` in detached head state
|
||||
if #branch == 0 then
|
||||
branch = "HEAD"
|
||||
end
|
||||
else
|
||||
-- `git branch --show-current` requires Git v2.22.0+ so going with more
|
||||
-- widely available command
|
||||
branch = M.get_os_command_output({
|
||||
"git",
|
||||
"rev-parse",
|
||||
"--abbrev-ref",
|
||||
"HEAD",
|
||||
})[1]
|
||||
end
|
||||
|
||||
if branch then
|
||||
return vim.loop.cwd() .. "-" .. branch
|
||||
|
|
Loading…
Reference in a new issue