2 from yap
import YapPlugin
3 from yap
.util
import get_output
, takes_options
7 class TCommitPlugin(YapPlugin
):
8 def __init__(self
, yap
):
11 def _add_branch(self
, branch
):
12 repo
= get_output("git rev-parse --git-dir")
15 state_file
= os
.path
.join(repo
[0], 'yap', 'tcommit')
17 b
= self
._get
_branches
()
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')
26 b
= pickle
.load(file(state_file
))
31 def _remove_branch(self
, branch
):
32 repo
= get_output("git rev-parse --git-dir")
35 state_file
= os
.path
.join(repo
[0], 'yap', 'tcommit')
37 b
= self
._get
_branches
()
39 pickle
.dump(b
, file(state_file
, 'w'))
42 def cmd_commit(self
, *args
, **flags
):
44 self
.yap
.cmd_commit(*[], **{'-a': 1, '-m': 'yap wip'})
45 branch
= get_output("git symbolic-ref HEAD")
47 self
._add
_branch
(branch
[0])
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])