diff --git a/cspell.json b/cspell.json new file mode 100644 index 0000000..39401ac --- /dev/null +++ b/cspell.json @@ -0,0 +1 @@ +{ "language": "en", "version": "0.2", "flagWords": [], "words": ["worktree", "gitdir"] } diff --git a/git.yazi/init.lua b/git.yazi/init.lua index 965628a..3cf79a8 100644 --- a/git.yazi/init.lua +++ b/git.yazi/init.lua @@ -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()