Skip to content

Commit c84f893

Browse files
committed
feat: update
1 parent d5b2fed commit c84f893

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

Diff for: git.yazi/main.lua

+32-36
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
---@enum Status
2424
local Status = {
25-
__ignored = 100,
2625
ignored = 6,
2726
untracked = 5,
2827
added = 4,
@@ -34,7 +33,7 @@ local Status = {
3433

3534
---@type table<string, Status>
3635
local PATTERNS = {
37-
{ "!$", Status.__ignored },
36+
{ "!$", Status.ignored },
3837
{ "?$", Status.untracked },
3938
{ "[AC]", Status.added },
4039
{ "[MT]", Status.modified },
@@ -64,6 +63,7 @@ local Config = {
6463
},
6564
}
6665

66+
local __ignored_dir__ = 100
6767
local is_windows = ya.target_family() == "windows"
6868

6969
---@param line string
@@ -113,13 +113,11 @@ end
113113
local function bubble_up(changes)
114114
local new, empty = {}, Url("")
115115
for path, status in pairs(changes) do
116-
if status ~= Status.ignored and status ~= Status.__ignored then
117-
local url = Url(path):parent()
118-
while url and url ~= empty do
119-
local s = tostring(url)
120-
new[s] = (new[s] or Status.unkonwn) > status and new[s] or status
121-
url = url:parent()
122-
end
116+
local url = Url(path):parent()
117+
while url and url ~= empty do
118+
local s = tostring(url)
119+
new[s] = (new[s] or Status.unkonwn) > status and new[s] or status
120+
url = url:parent()
123121
end
124122
end
125123
return new
@@ -128,15 +126,16 @@ end
128126
---@param ignored Changes
129127
---@param cwd Url
130128
---@param repo Url
129+
---@return Changes
131130
local function propagate_down(ignored, cwd, repo)
132131
local new, rel = {}, cwd:strip_prefix(repo)
133-
for path, status in pairs(ignored) do
134-
if status == Status.__ignored then
135-
if rel:starts_with(path) then
136-
new[tostring(repo:join(rel))] = Status.__ignored
137-
elseif cwd == repo:join(path):parent() then
138-
new[path] = Status.ignored
139-
end
132+
for _, path in ipairs(ignored) do
133+
if rel:starts_with(path) then
134+
-- if `cwd` is a subfolder of an ignored directory, mark the `cwd` as `__ignored_dir__`
135+
new[tostring(cwd)] = __ignored_dir__
136+
elseif cwd == repo:join(path):parent() then
137+
-- if `cwd` contains any ignored files or directories, mark them as `ignored`
138+
new[path] = Status.ignored
140139
end
141140
end
142141
return new
@@ -149,36 +148,40 @@ end
149148
local add = ya.sync(function(st, cwd, repo, changes)
150149
st.dirs_to_repo[cwd] = repo
151150
st.repos[repo] = st.repos[repo] or {}
151+
152152
for path, status in pairs(changes) do
153-
if status == Status.__ignored then
154-
st.dirs_to_repo[path] = ""
153+
if status == __ignored_dir__ then
154+
-- so that we can know if a file is in an ignored directory when handle linemode
155+
---@diagnostic disable-next-line: assign-type-mismatch
156+
st.dirs_to_repo[path] = __ignored_dir__
155157
else
156158
st.repos[repo][path] = status
157159
end
158160
end
161+
159162
ya.render()
160163
end)
161164

162165
---@param st PluginState
163166
---@param cwd FullPath
164167
local remove = ya.sync(function(st, cwd)
165-
local dir = st.dirs_to_repo[cwd]
166-
if not dir then
168+
local repo = st.dirs_to_repo[cwd]
169+
if not repo then
167170
return
168171
end
169172

170173
ya.render()
171174

172175
st.dirs_to_repo[cwd] = nil
173-
if not st.repos[dir] then
176+
if not st.repos[repo] then
174177
return
175178
end
176179
for _, r in pairs(st.dirs_to_repo) do
177-
if r == dir then
180+
if r == repo then
178181
return
179182
end
180183
end
181-
st.repos[dir] = nil
184+
st.repos[repo] = nil
182185
end)
183186

184187
---@param options SetupOptions
@@ -213,7 +216,7 @@ local function setup(st, opts)
213216
local repo = st.dirs_to_repo[tostring(url:parent())]
214217
local status
215218
if repo then
216-
status = repo == "" and Status.ignored or st.repos[repo][tostring(url):sub(#repo + 2)]
219+
status = repo == __ignored_dir__ and Status.ignored or st.repos[repo][tostring(url):sub(#repo + 2)]
217220
end
218221

219222
if not status or Config.icons[status] == "" then
@@ -241,18 +244,10 @@ local function fetch(_, job)
241244
paths[#paths + 1] = tostring(f.url)
242245
end
243246

247+
-- stylua: ignore
244248
local output, err = Command("git")
245249
:cwd(cwd)
246-
:args({
247-
"--no-optional-locks",
248-
"-c",
249-
"core.quotePath=",
250-
"status",
251-
"--porcelain",
252-
"-unormal",
253-
"--no-renames",
254-
"--ignored=matching",
255-
})
250+
:args({ "--no-optional-locks", "-c", "core.quotePath=", "status", "--porcelain", "-unormal", "--no-renames", "--ignored=matching" })
256251
:args(paths)
257252
:stdout(Command.PIPED)
258253
:output()
@@ -264,13 +259,14 @@ local function fetch(_, job)
264259
for line in output.stdout:gmatch("[^\r\n]+") do
265260
local status, path = match(line)
266261
if status and path then
267-
if status == Status.__ignored then
268-
ignored[path] = status
262+
if status == Status.ignored then
263+
ignored[#ignored + 1] = path
269264
else
270265
changes[path] = status
271266
end
272267
end
273268
end
269+
274270
if job.files[1].cha.is_dir then
275271
ya.dict_merge(changes, bubble_up(changes))
276272
end

0 commit comments

Comments
 (0)