Merge pull request #49 from Avimitin/fix-submodule
refactor: delete the wrong and useless path check
This commit is contained in:
@@ -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
|
||||||
|
if is_symlink() then
|
||||||
path = project_root_dir()
|
path = project_root_dir()
|
||||||
end
|
end
|
||||||
if path == nil or fn.isdirectory(path .. '/.git/') == 0 then
|
|
||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user