Skip to content

Commit a18981d

Browse files
committed
feat(actions): After restoring entry, write undo command to log
This way the undo command can always be found in `:DiffviewLog`. This is now also mentioned in the docs. Also run `:checktime` for the restored buffer.
1 parent 7e5a85c commit a18981d

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

doc/diffview.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ restore_entry *diffview-actions-restore_entry*
11411141
entry's commit.
11421142

11431143
NOTE: A command is echoed that shows how to undo the change. Check
1144-
|:messages| to see it again.
1144+
|:messages| or |:DiffviewLog| to see it again.
11451145

11461146
scroll_view({distance}) *diffview-actions-scroll_view*
11471147
Contexts: `panel`
@@ -1375,7 +1375,8 @@ X Revert the selected file entry to the state from the
13751375
left side of the diff. This only works if the right
13761376
side of the diff is showing the local state of the
13771377
file. A command is echoed that shows how to undo the
1378-
change. Check |:messages| to see it again.
1378+
change. Check |:messages| or |:DiffviewLog| to see it
1379+
again.
13791380

13801381
*diffview-maps-refresh_files*
13811382
R Update the stats and entries in the file list.

lua/diffview/vcs/adapters/git/init.lua

+4
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,10 @@ GitAdapter.file_restore = async.wrap(function(self, path, kind, commit, callback
15431543
utils.vec_join("checkout", commit or (kind == "staged" and "HEAD" or nil), "--", path),
15441544
self.ctx.toplevel
15451545
)
1546+
1547+
await(async.scheduler())
1548+
local bn = utils.find_file_buffer(abs_path)
1549+
if bn then vim.cmd(fmt("checktime %d", bn)) end
15461550
end
15471551

15481552
callback(true, undo)

lua/diffview/vcs/utils.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local utils = require("diffview.utils")
99
local api = vim.api
1010
local await = async.await
1111
local fmt = string.format
12+
local logger = DiffviewGlobal.logger
1213

1314
local M = {}
1415

@@ -160,7 +161,10 @@ M.restore_file = async.void(function(adapter, path, kind, commit)
160161
end
161162

162163
local rev_name = (commit and commit:sub(1, 11)) or (kind == "staged" and "HEAD" or "index")
163-
utils.info(fmt("File restored from %s. %s", rev_name, undo and "Undo with " .. undo), true)
164+
local msg = fmt("File restored from %s. %s", rev_name, undo and ("Undo with " .. undo) or "")
165+
166+
logger:info(msg)
167+
utils.info(msg, true)
164168
end)
165169

166170
--[[

0 commit comments

Comments
 (0)