From ab02b864db3b63f25568284ca47a33a59ea6b43a Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Sun, 12 Apr 2020 07:21:21 -0600 Subject: [PATCH] Try actual and symlinked files --- lua/lazygit.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 18ffb58..2726a98 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -13,7 +13,23 @@ local function is_lazygit_available() end local function project_root_dir() - return fn.finddir('.git/..', fn.expand('%:p:h') .. ';') + + -- try file location first + local gitdir = fn.system('cd ' .. fn.expand('%:p:h') .. ' && git rev-parse --show-toplevel') + local isgitdir = fn.matchstr(gitdir, '^fatal:.*') == "" + if isgitdir then + return gitdir + end + + -- try symlinked file location instead + local gitdir = fn.system('cd ' .. fn.fnamemodify(fn.resolve(fn.expand('%:p')), ':h') .. ' && git rev-parse --show-toplevel') + local isgitdir = fn.matchstr(gitdir, '^fatal:.*') == "" + if isgitdir then + return gitdir + end + + -- just return current working directory + return fn.getcwd() end local function exec_lazygit_command(root_dir)