svn: create a tagged blob with vital repository information
[yap.git] / plugins / tcommit.py
blobcc691235c0538cc73fa92d271d34cdc6f9e0f8c8
2 from yap import YapPlugin
3 from yap.util import get_output, takes_options
4 import pickle
5 import os
7 class TCommitPlugin(YapPlugin):
8 def __init__(self, yap):
9 self.yap = yap
11 def _add_branch(self, branch):
12 repo = get_output("git rev-parse --git-dir")
13 if not repo:
14 return
15 dir = os.path.join(repo[0], 'yap')
16 try:
17 os.mkdir(dir)
18 except OSError:
19 pass
20 state_file = os.path.join(dir, 'tcommit')
22 b = self._get_branches()
23 b.add(branch)
24 pickle.dump(b, file(state_file, 'w'))
26 def _get_branches(self):
27 repo = get_output("git rev-parse --git-dir")
28 state_file = os.path.join(repo[0], 'yap', 'tcommit')
30 try:
31 b = pickle.load(file(state_file))
32 except IOError:
33 b = set()
34 return b
36 def _remove_branch(self, branch):
37 repo = get_output("git rev-parse --git-dir")
38 if not repo:
39 return
40 state_file = os.path.join(repo[0], 'yap', 'tcommit')
42 b = self._get_branches()
43 b.remove(branch)
44 pickle.dump(b, file(state_file, 'w'))
46 @takes_options("t")
47 def cmd_commit(self, *args, **flags):
48 if '-t' in flags:
49 self.yap.cmd_commit(*[], **{'-a': 1, '-m': 'yap wip'})
50 branch = get_output("git symbolic-ref HEAD")
51 if branch:
52 self._add_branch(branch[0])
53 else:
54 self.yap._call_base("cmd_commit", *args, **flags)
56 def post_switch(self):
57 branch = get_output("git symbolic-ref HEAD")
58 if branch[0] in self._get_branches():
59 self.yap.cmd_uncommit()
60 self._remove_branch(branch[0])