Skip to content

fix repo recognition & add telescope support #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions lua/lazygit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ vim = vim
local api = vim.api
local fn = vim.fn


LAZYGIT_BUFFER = nil
LAZYGIT_LOADED = false
vim.g.lazygit_opened = 0
Expand All @@ -23,17 +24,17 @@ end

--- Get project_root_dir for git repository
local function project_root_dir()

-- always use bash on Unix based systems.
local oldshell = vim.o.shell
if vim.fn.has('win32') == 0 then
vim.o.shell = 'bash'
end

-- try symlinked file location instead
gitdir = fn.system(
local gitdir = fn.system(
'cd "' .. fn.fnamemodify(fn.resolve(fn.expand('%:p')), ':h') .. '" && git rev-parse --show-toplevel')
isgitdir = fn.matchstr(gitdir, '^fatal:.*') == ''
local isgitdir = fn.matchstr(gitdir, '^fatal:.*') == ''

if isgitdir then
vim.o.shell = oldshell
return trim(gitdir)
Expand Down Expand Up @@ -152,19 +153,21 @@ local function lazygit(path)
print('Please install lazygit. Check documentation for more information')
return
end

open_floating_window()

local cmd = 'lazygit'
-- set path to the root path
_ = project_root_dir()

if path == nil then
if is_symlink() then
path = project_root_dir()
end
else
cmd = cmd .. ' -p ' .. path
end
open_floating_window()
local cmd = 'lazygit'
if path ~= nil and not vim.env.GIT_DIR then
cmd = cmd .. ' -g "' .. path .. '/.git/"'
end
if path ~= nil and not vim.env.GIT_WORK_TREE then
cmd = cmd .. ' -w "' .. path .. '"'
end

exec_lazygit_command(cmd)
end

Expand Down