Skip to content
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

find bare root when creating worktrees #76

Closed
wants to merge 2 commits into from
Closed
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
37 changes: 16 additions & 21 deletions lua/git-worktree/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down