2121from urllib import parse as urlparse
2222
2323from libvcs ._internal .run import run
24- from libvcs ._internal .types import StrOrBytesPath , StrPath
24+ from libvcs ._internal .types import StrPath
25+ from libvcs .cmd .svn import Svn
2526
2627from .base import BaseSync
2728
@@ -32,25 +33,33 @@ class SvnSync(BaseSync):
3233 bin_name = "svn"
3334 schemes = ("svn" , "svn+ssh" , "svn+http" , "svn+https" , "svn+svn" )
3435
35- def __init__ (self , * , url : str , dir : StrPath , ** kwargs : Any ) -> None :
36+ def __init__ (
37+ self ,
38+ * ,
39+ url : str ,
40+ dir : StrPath ,
41+ ** kwargs : Any ,
42+ ) -> None :
3643 """A svn repository.
3744
3845 Parameters
3946 ----------
4047 url : str
4148 URL in subversion repository
4249
43- svn_username : str, optional
50+ username : str, optional
4451 username to use for checkout and update
4552
46- svn_password : str, optional
53+ password : str, optional
4754 password to use for checkout and update
4855
4956 svn_trust_cert : bool
5057 trust the Subversion server site certificate, default False
5158 """
52- if "svn_trust_cert" not in kwargs :
53- self .svn_trust_cert = False
59+ self .svn_trust_cert = kwargs .pop ("svn_trust_cert" , False )
60+
61+ self .username = kwargs .get ("username" )
62+ self .password = kwargs .get ("password" )
5463
5564 self .rev = kwargs .get ("rev" )
5665 super ().__init__ (url = url , dir = dir , ** kwargs )
@@ -63,18 +72,21 @@ def _user_pw_args(self) -> list[Any]:
6372 return args
6473
6574 def obtain (self , quiet : Optional [bool ] = None , * args : Any , ** kwargs : Any ) -> None :
66- self .ensure_dir ()
67-
6875 url , rev = self .url , self .rev
6976
70- cmd : list [StrOrBytesPath ] = ["checkout" , "-q" , url , "--non-interactive" ]
77+ if rev is not None :
78+ kwargs ["revision" ] = rev
7179 if self .svn_trust_cert :
72- cmd .append ("--trust-server-cert" )
73- cmd .extend (self ._user_pw_args ())
74- cmd .extend (get_rev_options (url , rev ))
75- cmd .append (self .dir )
76-
77- self .run (cmd )
80+ kwargs ["trust_server_cert" ] = True
81+ self .cmd .checkout (
82+ url = url ,
83+ username = self .username ,
84+ password = self .password ,
85+ non_interactive = True ,
86+ quiet = True ,
87+ check_returncode = True ,
88+ ** kwargs ,
89+ )
7890
7991 def get_revision_file (self , location : str ) -> int :
8092 """Return revision for a file."""
@@ -124,17 +136,15 @@ def update_repo(
124136 ) -> None :
125137 self .ensure_dir ()
126138 if pathlib .Path (self .dir / ".svn" ).exists ():
127- if dest is None :
128- dest = str (self .dir )
129-
130- url , rev = self .url , self .rev
131-
132- cmd = ["update" ]
133- cmd .extend (self ._user_pw_args ())
134- cmd .extend (get_rev_options (url , rev ))
135- cmd .append (dest )
136-
137- self .run (cmd )
139+ self .cmd .checkout (
140+ url = self .url ,
141+ username = self .username ,
142+ password = self .password ,
143+ non_interactive = True ,
144+ quiet = True ,
145+ check_returncode = True ,
146+ ** kwargs ,
147+ )
138148 else :
139149 self .obtain ()
140150 self .update_repo ()
@@ -190,6 +200,10 @@ def _get_svn_url_rev(cls, location: str) -> tuple[Optional[str], int]:
190200
191201 return url , rev
192202
203+ @property
204+ def cmd (self , * args : object , ** kwargs : object ) -> Svn :
205+ return Svn (dir = self .dir , * args , ** kwargs )
206+
193207
194208def get_rev_options (url : str , rev : None ) -> list [Any ]:
195209 """Return revision options. From pip pip.vcs.subversion."""
0 commit comments