1
+ local log = require (" oil.log" )
1
2
local M = {}
2
3
3
4
local uv = vim .uv or vim .loop
@@ -245,6 +246,37 @@ M.recursive_delete = function(entry_type, path, cb)
245
246
end , 10000 )
246
247
end
247
248
249
+ --- Move the undofile for the file at src_path to dest_path
250
+ --- @param src_path string
251
+ --- @param dest_path string
252
+ --- @param copy boolean
253
+ local move_undofile = vim .schedule_wrap (function (src_path , dest_path , copy )
254
+ local undofile = vim .fn .undofile (src_path )
255
+ uv .fs_stat (
256
+ undofile ,
257
+ vim .schedule_wrap (function (stat_err )
258
+ if stat_err then
259
+ -- undofile doesn't exist
260
+ return
261
+ end
262
+ local dest_undofile = vim .fn .undofile (dest_path )
263
+ if copy then
264
+ uv .fs_copyfile (src_path , dest_path , function (err )
265
+ if err then
266
+ log .warn (" Error copying undofile %s: %s" , undofile , err )
267
+ end
268
+ end )
269
+ else
270
+ uv .fs_rename (undofile , dest_undofile , function (err )
271
+ if err then
272
+ log .warn (" Error moving undofile %s: %s" , undofile , err )
273
+ end
274
+ end )
275
+ end
276
+ end )
277
+ )
278
+ end )
279
+
248
280
--- @param entry_type oil.EntryType
249
281
--- @param src_path string
250
282
--- @param dest_path string
@@ -262,6 +294,7 @@ M.recursive_copy = function(entry_type, src_path, dest_path, cb)
262
294
end
263
295
if entry_type ~= " directory" then
264
296
uv .fs_copyfile (src_path , dest_path , { excl = true }, cb )
297
+ move_undofile (src_path , dest_path , true )
265
298
return
266
299
end
267
300
uv .fs_stat (src_path , function (stat_err , src_stat )
@@ -333,6 +366,9 @@ M.recursive_move = function(entry_type, src_path, dest_path, cb)
333
366
end
334
367
end )
335
368
else
369
+ if entry_type ~= " directory" then
370
+ move_undofile (src_path , dest_path , false )
371
+ end
336
372
cb ()
337
373
end
338
374
end )
0 commit comments