22
22
23
23
--- @enum Status
24
24
local Status = {
25
- __ignored = 100 ,
26
25
ignored = 6 ,
27
26
untracked = 5 ,
28
27
added = 4 ,
@@ -34,7 +33,7 @@ local Status = {
34
33
35
34
--- @type table<string , Status>
36
35
local PATTERNS = {
37
- { " !$" , Status .__ignored },
36
+ { " !$" , Status .ignored },
38
37
{ " ?$" , Status .untracked },
39
38
{ " [AC]" , Status .added },
40
39
{ " [MT]" , Status .modified },
@@ -64,6 +63,7 @@ local Config = {
64
63
},
65
64
}
66
65
66
+ local __ignored_dir__ = 100
67
67
local is_windows = ya .target_family () == " windows"
68
68
69
69
--- @param line string
@@ -113,13 +113,11 @@ end
113
113
local function bubble_up (changes )
114
114
local new , empty = {}, Url (" " )
115
115
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 ()
123
121
end
124
122
end
125
123
return new
@@ -128,15 +126,16 @@ end
128
126
--- @param ignored Changes
129
127
--- @param cwd Url
130
128
--- @param repo Url
129
+ --- @return Changes
131
130
local function propagate_down (ignored , cwd , repo )
132
131
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
140
139
end
141
140
end
142
141
return new
@@ -149,36 +148,40 @@ end
149
148
local add = ya .sync (function (st , cwd , repo , changes )
150
149
st .dirs_to_repo [cwd ] = repo
151
150
st .repos [repo ] = st .repos [repo ] or {}
151
+
152
152
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__
155
157
else
156
158
st .repos [repo ][path ] = status
157
159
end
158
160
end
161
+
159
162
ya .render ()
160
163
end )
161
164
162
165
--- @param st PluginState
163
166
--- @param cwd FullPath
164
167
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
167
170
return
168
171
end
169
172
170
173
ya .render ()
171
174
172
175
st .dirs_to_repo [cwd ] = nil
173
- if not st .repos [dir ] then
176
+ if not st .repos [repo ] then
174
177
return
175
178
end
176
179
for _ , r in pairs (st .dirs_to_repo ) do
177
- if r == dir then
180
+ if r == repo then
178
181
return
179
182
end
180
183
end
181
- st .repos [dir ] = nil
184
+ st .repos [repo ] = nil
182
185
end )
183
186
184
187
--- @param options SetupOptions
@@ -213,7 +216,7 @@ local function setup(st, opts)
213
216
local repo = st .dirs_to_repo [tostring (url :parent ())]
214
217
local status
215
218
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 )]
217
220
end
218
221
219
222
if not status or Config .icons [status ] == " " then
@@ -241,18 +244,10 @@ local function fetch(_, job)
241
244
paths [# paths + 1 ] = tostring (f .url )
242
245
end
243
246
247
+ -- stylua: ignore
244
248
local output , err = Command (" git" )
245
249
: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" })
256
251
:args (paths )
257
252
:stdout (Command .PIPED )
258
253
:output ()
@@ -264,13 +259,14 @@ local function fetch(_, job)
264
259
for line in output .stdout :gmatch (" [^\r\n ]+" ) do
265
260
local status , path = match (line )
266
261
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
269
264
else
270
265
changes [path ] = status
271
266
end
272
267
end
273
268
end
269
+
274
270
if job .files [1 ].cha .is_dir then
275
271
ya .dict_merge (changes , bubble_up (changes ))
276
272
end
0 commit comments