feat: Allow current buffer commits to show on the already worked out Git root (#148)
We have already worked out the "git root" for the current buffer, we did
this to work out the relative path. We might as well use this
information when calling `lazygitfilter`.
This now allows `lazygitfiltercurrentfile` to work, whether your actual
cwd is a git repository ('normal' workflow) or a project folder
containing many repositories (another workflow many vim users follow).
It looks like LSP did an autoformat on the file also, I can revert those
two lines if required.
This commit is contained in:
@@ -108,7 +108,7 @@ local function lazygitlog(path)
|
|||||||
if type(config_path) == "table" then
|
if type(config_path) == "table" then
|
||||||
config_path = table.concat(config_path, ",")
|
config_path = table.concat(config_path, ",")
|
||||||
end
|
end
|
||||||
cmd = cmd .. " -ucf '" .. config_path .. "'" -- quote config_path to avoid whitespace errors
|
cmd = cmd .. ' -ucf "' .. config_path .. '"' -- quote config_path to avoid whitespace errors
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.env.GIT_DIR ~= nil and vim.env.GIT_WORK_TREE ~= nil then
|
if vim.env.GIT_DIR ~= nil and vim.env.GIT_WORK_TREE ~= nil then
|
||||||
@@ -147,7 +147,7 @@ local function lazygit(path)
|
|||||||
if type(config_path) == "table" then
|
if type(config_path) == "table" then
|
||||||
config_path = table.concat(config_path, ",")
|
config_path = table.concat(config_path, ",")
|
||||||
end
|
end
|
||||||
cmd = cmd .. " -ucf '" .. config_path .. "'" -- quote config_path to avoid whitespace errors
|
cmd = cmd .. ' -ucf "' .. config_path .. '"' -- quote config_path to avoid whitespace errors
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.env.GIT_DIR ~= nil and vim.env.GIT_WORK_TREE ~= nil then
|
if vim.env.GIT_DIR ~= nil and vim.env.GIT_WORK_TREE ~= nil then
|
||||||
@@ -173,7 +173,7 @@ local function lazygitcurrentfile()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- :LazyGitFilter entry point
|
--- :LazyGitFilter entry point
|
||||||
local function lazygitfilter(path)
|
local function lazygitfilter(path, git_root)
|
||||||
if is_lazygit_available() ~= true then
|
if is_lazygit_available() ~= true then
|
||||||
print("Please install lazygit. Check documentation for more information")
|
print("Please install lazygit. Check documentation for more information")
|
||||||
return
|
return
|
||||||
@@ -183,7 +183,11 @@ local function lazygitfilter(path)
|
|||||||
end
|
end
|
||||||
prev_win = vim.api.nvim_get_current_win()
|
prev_win = vim.api.nvim_get_current_win()
|
||||||
win, buffer = open_floating_window()
|
win, buffer = open_floating_window()
|
||||||
local cmd = "lazygit " .. "-f " .. "'" .. path .. "'"
|
|
||||||
|
local cmd = "lazygit " .. '-f "' .. path .. '"'
|
||||||
|
if git_root then
|
||||||
|
cmd = cmd .. ' -p "' .. git_root .. '"'
|
||||||
|
end
|
||||||
exec_lazygit_command(cmd)
|
exec_lazygit_command(cmd)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -193,7 +197,7 @@ local function lazygitfiltercurrentfile()
|
|||||||
local git_root = get_root(current_dir)
|
local git_root = get_root(current_dir)
|
||||||
local file_path = vim.fn.expand("%:p")
|
local file_path = vim.fn.expand("%:p")
|
||||||
local relative_path = string.sub(file_path, #git_root + 2)
|
local relative_path = string.sub(file_path, #git_root + 2)
|
||||||
lazygitfilter(relative_path)
|
lazygitfilter(relative_path, git_root)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- :LazyGitConfig entry point
|
--- :LazyGitConfig entry point
|
||||||
|
|||||||
Reference in New Issue
Block a user