114
114
115
115
local function get_changed_files ()
116
116
local files = {}
117
- local git_files = git .list_changed_files ()
118
117
local snapshot_base = get_snapshot_dir ()
119
118
119
+ if not snapshot_base :exists () then return files end
120
+
121
+ local git_files = git .list_changed_files ()
120
122
for file in git_files :gmatch (" [^\n ]+" ) do
121
123
local snapshot_file = snapshot_base :joinpath (file )
122
124
@@ -185,6 +187,13 @@ local function show_file_diff(file_path, snapshot_path)
185
187
})
186
188
end
187
189
190
+ local function display_file_at_index (idx )
191
+ local file_data = M .__changed_files [idx ]
192
+ local file_name = vim .fn .fnamemodify (file_data [1 ], " :t" )
193
+ vim .notify (string.format (" Showing file %d of %d: %s" , idx , # M .__changed_files , file_name ))
194
+ show_file_diff (file_data [1 ], file_data [2 ])
195
+ end
196
+
188
197
-- Public functions
189
198
190
199
M .review = require_git_project (function ()
@@ -221,10 +230,7 @@ M.next_diff = require_git_project(function()
221
230
M .__current_file_index = M .__current_file_index + 1
222
231
end
223
232
224
- local idx = M .__current_file_index
225
- local file_data = M .__changed_files [idx ]
226
- vim .notify (string.format (" Showing file %d of %d: %s" , idx , # M .__changed_files , file_data [1 ]))
227
- show_file_diff (file_data [1 ], file_data [2 ])
233
+ display_file_at_index (M .__current_file_index )
228
234
end )
229
235
230
236
M .prev_diff = require_git_project (function ()
@@ -243,16 +249,23 @@ M.prev_diff = require_git_project(function()
243
249
end
244
250
end
245
251
246
- local idx = M .__current_file_index
247
- local file_data = M .__changed_files [idx ]
248
- vim .notify (string.format (" Showing file %d of %d: %s" , idx , # M .__changed_files , file_data [1 ]))
249
- show_file_diff (file_data [1 ], file_data [2 ])
252
+ display_file_at_index (M .__current_file_index )
250
253
end )
251
254
252
255
M .close_diff = function ()
253
256
close_diff_tab ()
254
257
end
255
258
259
+ M .check_cleanup_breakpoint = function ()
260
+ local changed_files = get_changed_files ()
261
+ if # changed_files == 0 then
262
+ local snapshot_base = get_snapshot_dir ()
263
+ if snapshot_base :exists () then
264
+ snapshot_base :rm ({ recursive = true })
265
+ end
266
+ end
267
+ end
268
+
256
269
M .set_breakpoint = require_git_project (function ()
257
270
local snapshot_base = get_snapshot_dir ()
258
271
@@ -323,4 +336,4 @@ M.reset_git_status = function()
323
336
M .__is_git_project = nil
324
337
end
325
338
326
- return M
339
+ return M
0 commit comments