From 148d19ca7a2e86088ef1f13d4b69e0dae3901e3e Mon Sep 17 00:00:00 2001 From: f Date: Sun, 21 Nov 2021 10:51:23 +0800 Subject: [PATCH 1/3] fix: git rev-parse --show-superproject-working-tree return `fatal: not a git repository (or any of the parent directories): .git` when execute not in a git repo --- lua/lazygit.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index ec2001b..dca0d38 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -27,7 +27,7 @@ local function project_root_dir() -- try submodule first local gitdir = fn.system('cd "' .. fn.expand('%:p:h') .. '" && git rev-parse --show-superproject-working-tree') - if gitdir ~= '' then + if gitdir ~= '' and fn.matchstr(gitdir, '^fatal:.*') == '' then vim.o.shell = oldshell return trim(gitdir) end From 940495546ff1fe3a6bedfdd0954fff17017a23a2 Mon Sep 17 00:00:00 2001 From: f Date: Sun, 21 Nov 2021 13:12:22 +0800 Subject: [PATCH 2/3] fix: to check path exists. lazygit -g "notExistPath" will error: *fs.PathError stat /xxxxxx/.git/: no such file or directory --- lua/lazygit.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index dca0d38..45e125f 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -165,6 +165,9 @@ local function lazygit(path) if path == nil then path = project_root_dir() end + if path == nil or not fn.isdirectory(path .. '/.git/') then + print('Not in a git repository') + end open_floating_window() local cmd = 'lazygit' if not vim.env.GIT_DIR then From 18d121833bc7b612d216261436946240f916f21f Mon Sep 17 00:00:00 2001 From: f Date: Sun, 21 Nov 2021 14:09:52 +0800 Subject: [PATCH 3/3] vim.fn.isdirectory(..) return 0/1 --- lua/lazygit.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 45e125f..5ce99bb 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -165,8 +165,9 @@ local function lazygit(path) if path == nil then path = project_root_dir() end - if path == nil or not fn.isdirectory(path .. '/.git/') then + if path == nil or fn.isdirectory(path .. '/.git/') == 0 then print('Not in a git repository') + return end open_floating_window() local cmd = 'lazygit'