Revert "cmd_unstage: work correctly from a subdirectory"
[yap.git] / plugins / backup.py
blobda40dd1752a2c81271a43f6f29be67337e01c407
2 from yap.yap import YapCore, YapError
3 from yap.util import run_command
4 import os
6 class BackupPlugin(YapCore):
7 "Save a backup of files before reverting them"
9 def cmd_revert(self, *args, **flags):
10 files = set(args)
11 changed = set(self._get_staged_files() + self._get_unstaged_files())
13 if '-a' in flags:
14 files = changed
15 else:
16 files = files.intersection(changed)
18 files = [ x for x in files if os.access(x, os.R_OK) ]
20 for f in files:
21 run_command("cp %s %s~" % (f, f))
22 super(BackupPlugin, self).cmd_revert(*args, **flags)