From 4fcd737db5f6cd4b5d6645659b16d891e1d93dd3 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Thu, 24 Oct 2024 06:10:43 +0800 Subject: [PATCH] feat: support git worktree, closes #29 --- cspell.json | 1 + git.yazi/init.lua | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 cspell.json 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()