2 from yap
import YapPlugin
, YapError
3 from yap
.util
import get_output
, takes_options
, run_command
, short_help
6 class SvnPlugin(YapPlugin
):
7 def __init__(self
, yap
):
10 def _clone_svn(self
, url
, directory
=None, **flags
):
13 directory
= url
.rsplit('/')[-1]
14 directory
= directory
.replace('.git', '')
19 raise YapError("Directory exists: %s" % directory
)
22 os
.system("git svn init %s" % url
)
24 os
.system("git svn fetch -r %s:" % flags
['-r'])
26 os
.system("git svn fetch")
27 self
.yap
.cmd_repo("svn", url
)
28 os
.system("git config yap.svn.enabled 1")
31 enabled
= get_output("git config yap.svn.enabled")
34 def _get_svn_ref(self
):
35 fetch
= get_output("git config svn-remote.svn.fetch")
37 raise YapError("No svn remote configured")
38 ref
= fetch
[0].split(':')[1]
41 # Ensure users don't accidentally kill our "svn" repo
42 def pre_repo(self
, *args
, **flags
):
43 if not self
._enabled
():
45 if '-d' in flags
and args
and args
[0] == "svn":
46 raise YapError("Refusing to delete special svn repository")
49 def cmd_clone(self
, *args
, **flags
):
50 if args
and not run_command("svn info %s" % args
[0]):
51 self
._clone
_svn
(*args
, **flags
)
53 self
.yap
._call
_base
("cmd_commit", *args
, **flags
)
55 def cmd_fetch(self
, *args
, **flags
):
57 if args
and args
[0] == 'svn':
58 os
.system("git svn fetch")
60 self
.yap
._call
_base
("cmd_fetch", *args
, **flags
)
62 def cmd_push(self
, *args
, **flags
):
64 if args
and args
[0] == 'svn':
65 print "Verifying branch is up-to-date"
66 self
.yap
.cmd_fetch("svn")
67 ref
= self
._get
_svn
_ref
()
68 rev
= get_output("git rev-parse %s" % ref
)
70 base
= get_output("git merge-base HEAD %s" % rev
[0])
72 raise YapError("Branch not up-to-date. Update first.")
73 self
.yap
._confirm
_push
(current
, "trunk", "svn")
74 os
.system("git svn dcommit")
76 self
.yap
._call
_base
("cmd_push", *args
, **flags
)
78 @short_help("change options for the svn plugin")
79 def cmd_svn(self
, subcmd
):
82 if subcmd
not in ["enable"]:
85 if "svn" not in [x
[0] for x
in self
._list
_remotes
()]:
86 raise YapError("The svn plugin requires a remote named 'svn'")
88 os
.system("git config yap.svn.enabled 1")