Be stricter in globbing remote repositories
[yap.git] / plugins / tcommit.py
blob2173bb3d4aa199dcefb9720026a64e7fc3daca8b
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 state_file = os.path.join(repo[0], 'yap', 'tcommit')
17 b = self._get_branches()
18 b.add(branch)
19 pickle.dump(b, file(state_file, 'w'))
21 def _get_branches(self):
22 repo = get_output("git rev-parse --git-dir")
23 state_file = os.path.join(repo[0], 'yap', 'tcommit')
25 try:
26 b = pickle.load(file(state_file))
27 except IOError:
28 b = set()
29 return b
31 def _remove_branch(self, branch):
32 repo = get_output("git rev-parse --git-dir")
33 if not repo:
34 return
35 state_file = os.path.join(repo[0], 'yap', 'tcommit')
37 b = self._get_branches()
38 b.remove(branch)
39 pickle.dump(b, file(state_file, 'w'))
41 @takes_options("t")
42 def cmd_commit(self, *args, **flags):
43 if '-t' in flags:
44 self.yap.cmd_commit(*[], **{'-a': 1, '-m': 'yap wip'})
45 branch = get_output("git symbolic-ref HEAD")
46 if branch:
47 self._add_branch(branch[0])
48 else:
49 self.yap.cmd_commit(*args, **flags)
51 def post_switch(self):
52 branch = get_output("git symbolic-ref HEAD")
53 if branch[0] in self._get_branches():
54 self.yap.cmd_uncommit()
55 self._remove_branch(branch[0])