diff --git a/lua/git-worktree/init.lua b/lua/git-worktree/init.lua index 0fb5295..b0fefb2 100644 --- a/lua/git-worktree/init.lua +++ b/lua/git-worktree/init.lua @@ -32,36 +32,31 @@ M.setup_git_info = function() }) local process_find_git_dir = function(stdout) - if is_in_worktree then - -- if in worktree git dir returns absolute path - - -- try to find the dot git folder (non-bare repo) - local git_dir = Path:new(stdout) - local has_dot_git = false - for _, dir in ipairs(git_dir:_split()) do - if dir == ".git" then - has_dot_git = true - break - end + local git_dir = Path:new(stdout) + local has_dot_git = false + for _, dir in ipairs(git_dir:_split()) do + if dir == ".git" then + has_dot_git = true + break end + end + if is_in_worktree then + -- try to find the dot git folder (non-bare repo) if has_dot_git then - if stdout == ".git" then - git_worktree_root = cwd - else - local start = stdout:find("%.git") - git_worktree_root = stdout:sub(1,start - 2) - end + local start = stdout:find("%.git") + git_worktree_root = stdout:sub(1,start - 2) else local start = stdout:find("/worktrees/") git_worktree_root = stdout:sub(0, start - 1) end - elseif stdout == "." then - -- we are in the root git dir - git_worktree_root = cwd else - -- if not in worktree git dir should be absolute + if has_dot_git then + local start = stdout:find("%.git") + git_worktree_root = stdout:sub(1,start - 2) + else git_worktree_root = stdout + end end status:log():debug("git directory is: " .. git_worktree_root) end