backup: be quiet if the file doesn't exist
[yap.git] / plugins / backup.py
blob4dd2747a39ab86f3503df8ec5aa98e317730964b
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 x = changed
15 else:
16 x = files.intersection(changed)
18 for f in x:
19 run_command("cp %s %s~" % (f, f))
20 super(BackupPlugin, self).cmd_revert(*args, **flags)