2 from yap
import YapPlugin
3 from yap
.util
import get_output
, takes_options
7 class TCommitPlugin(YapPlugin
):
8 "Provide a 'temporory commit' mechanism"
10 def __init__(self
, yap
):
13 def _add_branch(self
, branch
):
14 repo
= get_output("git rev-parse --git-dir")
17 dir = os
.path
.join(repo
[0], 'yap')
22 state_file
= os
.path
.join(dir, 'tcommit')
24 b
= self
._get
_branches
()
26 pickle
.dump(b
, file(state_file
, 'w'))
28 def _get_branches(self
):
29 repo
= get_output("git rev-parse --git-dir")
30 state_file
= os
.path
.join(repo
[0], 'yap', 'tcommit')
33 b
= pickle
.load(file(state_file
))
38 def _remove_branch(self
, branch
):
39 repo
= get_output("git rev-parse --git-dir")
42 state_file
= os
.path
.join(repo
[0], 'yap', 'tcommit')
44 b
= self
._get
_branches
()
46 pickle
.dump(b
, file(state_file
, 'w'))
49 def cmd_commit(self
, *args
, **flags
):
51 self
.yap
.cmd_commit(*[], **{'-a': 1, '-m': 'yap wip'})
52 branch
= get_output("git symbolic-ref HEAD")
54 self
._add
_branch
(branch
[0])
56 self
.yap
._call
_base
("cmd_commit", *args
, **flags
)
58 def post_switch(self
):
59 branch
= get_output("git symbolic-ref HEAD")
60 if branch
[0] in self
._get
_branches
():
61 self
.yap
.cmd_uncommit()
62 self
._remove
_branch
(branch
[0])