refactor: delete the wrong and useless path check

The file path check is incorrect. It gives the main repository path to
lazygit, not the submodule path. Lazygit itself can do well for the
path-checking job, so just let lazygit deal with it.

Symlink check functionality is kept.

Signed-off-by: Avimitin <avimitin@gmail.com>
This commit is contained in:
Avimitin
2022-01-04 15:46:44 +08:00
parent 497ef5578e
commit 133ed492da

View File

@@ -16,6 +16,11 @@ local function is_lazygit_available()
return fn.executable('lazygit') == 1 return fn.executable('lazygit') == 1
end end
local function is_symlink()
local resolved = fn.resolve(fn.expand('%:p'))
return resolved ~= fn.expand('%:p')
end
--- Get project_root_dir for git repository --- Get project_root_dir for git repository
local function project_root_dir() local function project_root_dir()
@@ -25,21 +30,6 @@ local function project_root_dir()
vim.o.shell = 'bash' vim.o.shell = 'bash'
end end
-- try submodule first
local gitdir = fn.system('cd "' .. fn.expand('%:p:h') .. '" && git rev-parse --show-superproject-working-tree')
if gitdir ~= '' and fn.matchstr(gitdir, '^fatal:.*') == '' then
vim.o.shell = oldshell
return trim(gitdir)
end
-- 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
vim.o.shell = oldshell
return trim(gitdir)
end
-- try symlinked file location instead -- try symlinked file location instead
gitdir = fn.system( gitdir = fn.system(
'cd "' .. fn.fnamemodify(fn.resolve(fn.expand('%:p')), ':h') .. '" && git rev-parse --show-toplevel') 'cd "' .. fn.fnamemodify(fn.resolve(fn.expand('%:p')), ':h') .. '" && git rev-parse --show-toplevel')
@@ -163,18 +153,16 @@ local function lazygit(path)
return return
end end
if path == nil then if path == nil then
path = project_root_dir() if is_symlink() then
end path = project_root_dir()
if path == nil or fn.isdirectory(path .. '/.git/') == 0 then end
print('Not in a git repository')
return
end end
open_floating_window() open_floating_window()
local cmd = 'lazygit' local cmd = 'lazygit'
if not vim.env.GIT_DIR then if path ~= nil and not vim.env.GIT_DIR then
cmd = cmd .. ' -g "' .. path .. '/.git/"' cmd = cmd .. ' -g "' .. path .. '/.git/"'
end end
if not vim.env.GIT_WORK_TREE then if path ~= nil and not vim.env.GIT_WORK_TREE then
cmd = cmd .. ' -w "' .. path .. '"' cmd = cmd .. ' -w "' .. path .. '"'
end end
exec_lazygit_command(cmd) exec_lazygit_command(cmd)