feat: support git worktree, closes #29

This commit is contained in:
sxyazi
2024-10-24 06:10:43 +08:00
parent 4f1d0ae086
commit 4fcd737db5
2 changed files with 13 additions and 2 deletions

1
cspell.json Normal file
View File

@@ -0,0 +1 @@
{ "language": "en", "version": "0.2", "flagWords": [], "words": ["worktree", "gitdir"] }

View File

@@ -27,9 +27,19 @@ local function match(line)
end
local function root(cwd)
local is_worktree = function(url)
local file, head = io.open(tostring(url)), nil
if file then
head = file:read(8)
file:close()
end
return head == "gitdir: "
end
repeat
local cha = fs.cha(cwd:join(".git"))
if cha and cha.is_dir then
local next = cwd:join(".git")
local cha = fs.cha(next)
if cha and (cha.is_dir or is_worktree(next)) then
return tostring(cwd)
end
cwd = cwd:parent()