From c2a8b51c390c2cfb411289915e51160cfbf19685 Mon Sep 17 00:00:00 2001 From: Steven Walter Date: Mon, 7 Jul 2008 21:40:51 -0400 Subject: [PATCH] A simple backup plugin This plugin registers a pre-hook on revert and creates backup files for files that have uncommitted changes in them. --- plugins/backup.py | 18 ++++++++++++++++++ yap/__init__.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 plugins/backup.py diff --git a/plugins/backup.py b/plugins/backup.py new file mode 100644 index 0000000..fc4dc9d --- /dev/null +++ b/plugins/backup.py @@ -0,0 +1,18 @@ + +from yap import YapPlugin, YapError +import os + +class BackupPlugin(YapPlugin): + def __init__(self, yap): + self.yap = yap + + def pre_revert(self, *args, **flags): + files = set(args) + changed = set(self.yap._get_staged_files() + self.yap._get_unstaged_files()) + if '-a' in flags: + x = changed + else: + x = files.intersection(changed) + + for f in x: + os.system("cp %s %s~" % (f, f)) diff --git a/yap/__init__.py b/yap/__init__.py index 6a9bff9..9459f2a 100644 --- a/yap/__init__.py +++ b/yap/__init__.py @@ -1,2 +1,2 @@ -from yap import Yap +from yap import Yap, YapError from plugin import YapPlugin -- 2.11.4.GIT