From f5bf980373070760d6c1018f8443630dbbc5d7ac Mon Sep 17 00:00:00 2001 From: Rosen Stoyanov Date: Sat, 8 Apr 2023 22:59:55 +0300 Subject: [PATCH] feat: Use fugitive for faster branch name resolution --- lua/harpoon/utils.lua | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lua/harpoon/utils.lua b/lua/harpoon/utils.lua index 1252569..273289b 100644 --- a/lua/harpoon/utils.lua +++ b/lua/harpoon/utils.lua @@ -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