From 7672859d9c3d5e0445e7e8702a36a0e951cbdba8 Mon Sep 17 00:00:00 2001 From: "Joel D. Elkins" Date: Thu, 21 Jan 2021 12:27:02 -0600 Subject: [PATCH] Don't use -p if GIT_DIR or GIT_WORK_TREE are set Setting `-p ` is the same as setting `-w -g /.git/`, but this eliminates the possibility that the git dir could be outside of the work tree, or else named something besides `.git`. Use case for me is my configuration files are VC'ed in a git repo, and checked out into `$HOME` (the work tree). The repo is a bare repo elsewhere. --- lua/lazygit.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 71c4925..47b7644 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -147,7 +147,13 @@ local function lazygit(path) path = project_root_dir() end open_floating_window() - local cmd = "lazygit " .. "-p " .. path + local cmd = "lazygit" + if not vim.env.GIT_DIR then + cmd = cmd .. " -g " .. path .. "/.git/" + end + if not vim.env.GIT_WORK_TREE then + cmd = cmd .. " -w " .. path + end exec_lazygit_command(cmd) end