Skip to content

Commit ca814d5

Browse files
committed
cmds: add a proper RevertUnstagedEdits command
Signed-off-by: David Aguilar <davvid@gmail.com>
1 parent 384da2c commit ca814d5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

cola/cmds.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,36 @@ def do(self):
286286
self.model.update_file_status()
287287

288288

289+
class RevertUnstagedEdits(Command):
290+
291+
SHORTCUT = 'Ctrl+U'
292+
293+
def do(self):
294+
if not self.model.undoable():
295+
return
296+
s = selection.selection()
297+
if s.staged:
298+
items_to_undo = s.staged
299+
else:
300+
items_to_undo = s.modified
301+
if items_to_undo:
302+
if not Interaction.confirm(N_('Revert Unstaged Changes?'),
303+
N_('This operation drops unstaged changes.\n'
304+
'These changes cannot be recovered.'),
305+
N_('Revert the unstaged changes?'),
306+
N_('Revert Unstaged Changes'),
307+
default=True,
308+
icon=resources.icon('undo.svg')):
309+
return
310+
args = []
311+
if not s.staged and self.model.amending():
312+
args.append(self.model.head)
313+
do(Checkout, args + ['--'] + items_to_undo)
314+
else:
315+
msg = N_('No files selected for checkout from HEAD.')
316+
Interaction.log(msg)
317+
318+
289319
class Commit(ResetMode):
290320
"""Attempt to create a new commit."""
291321

0 commit comments

Comments
 (0)