From ce5917a58965b47ed09462ddb5d160dee2b130ae Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 27 Mar 2024 10:20:51 +0100 Subject: [PATCH] fix(lazygit): error handling for getting lazygit's config path --- lua/lazyvim/util/lazygit.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/util/lazygit.lua b/lua/lazyvim/util/lazygit.lua index c51af485..0b751f68 100644 --- a/lua/lazyvim/util/lazygit.lua +++ b/lua/lazyvim/util/lazygit.lua @@ -38,8 +38,22 @@ function M.open(opts) if M.dirty then M.update_config() end - M.config_dir = M.config_dir or vim.trim(vim.fn.system("lazygit -cd")) - vim.env.LG_CONFIG_FILE = M.config_dir .. "/config.yml" .. "," .. M.theme_path + + if not M.config_dir then + local Process = require("lazy.manage.process") + local ok, lines = pcall(Process.exec, { "lazygit", "-cd" }) + if ok then + M.config_dir = lines[1] + vim.env.LG_CONFIG_FILE = M.config_dir .. "/config.yml" .. "," .. M.theme_path + else + ---@diagnostic disable-next-line: cast-type-mismatch + ---@cast lines string + LazyVim.error( + { "Failed to get **lazygit** config directory.", "Will not apply **lazygit** config.", "", "# Error:", lines }, + { title = "lazygit" } + ) + end + end end return LazyVim.terminal(cmd, opts)