Skip to content

Commit d60ae3b

Browse files
committed
feat: auto clear diff breakpoint
1 parent 89eff6e commit d60ae3b

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

lua/goose/core.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ function M.run(prompt, opts)
9393
end,
9494
on_exit = function()
9595
state.goose_run_job = nil
96+
require('goose.review').check_cleanup_breakpoint()
9697
end
9798
}
9899
)

lua/goose/review.lua

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ end
114114

115115
local function get_changed_files()
116116
local files = {}
117-
local git_files = git.list_changed_files()
118117
local snapshot_base = get_snapshot_dir()
119118

119+
if not snapshot_base:exists() then return files end
120+
121+
local git_files = git.list_changed_files()
120122
for file in git_files:gmatch("[^\n]+") do
121123
local snapshot_file = snapshot_base:joinpath(file)
122124

@@ -185,6 +187,13 @@ local function show_file_diff(file_path, snapshot_path)
185187
})
186188
end
187189

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+
188197
-- Public functions
189198

190199
M.review = require_git_project(function()
@@ -221,10 +230,7 @@ M.next_diff = require_git_project(function()
221230
M.__current_file_index = M.__current_file_index + 1
222231
end
223232

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)
228234
end)
229235

230236
M.prev_diff = require_git_project(function()
@@ -243,16 +249,23 @@ M.prev_diff = require_git_project(function()
243249
end
244250
end
245251

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)
250253
end)
251254

252255
M.close_diff = function()
253256
close_diff_tab()
254257
end
255258

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+
256269
M.set_breakpoint = require_git_project(function()
257270
local snapshot_base = get_snapshot_dir()
258271

@@ -323,4 +336,4 @@ M.reset_git_status = function()
323336
M.__is_git_project = nil
324337
end
325338

326-
return M
339+
return M

0 commit comments

Comments
 (0)