Skip to content

Commit 834096c

Browse files
committed
feat(cmd[svn]): More SVN command support
1 parent 190106e commit 834096c

File tree

1 file changed

+77
-7
lines changed

1 file changed

+77
-7
lines changed

src/libvcs/cmd/svn.py

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99
import pathlib
1010
from collections.abc import Sequence
11-
from typing import Any, Literal, Optional, Union
11+
from typing import Any, List, Literal, Optional, Union
1212

1313
from libvcs._internal.run import run
1414
from libvcs._internal.types import StrOrBytesPath, StrPath
@@ -55,6 +55,9 @@ def run(
5555
trust_server_cert: Optional[bool] = None,
5656
config_dir: Optional[pathlib.Path] = None,
5757
config_option: Optional[pathlib.Path] = None,
58+
# Special behavior
59+
make_parents: Optional[bool] = True,
60+
check_returncode: Optional[bool] = None,
5861
**kwargs: Any,
5962
) -> str:
6063
"""
@@ -86,6 +89,10 @@ def run(
8689
--config-option, ``FILE:SECTION:OPTION=[VALUE]``
8790
cwd : :attr:`libvcs._internal.types.StrOrBytesPath`, optional
8891
Defaults to :attr:`~.cwd`
92+
make_parents : bool, default: ``True``
93+
Creates checkout directory (`:attr:`self.dir`) if it doesn't already exist.
94+
check_returncode : bool, default: ``None``
95+
Passthrough to :meth:`Svn.run`
8996
9097
Examples
9198
--------
@@ -117,7 +124,11 @@ def run(
117124
if config_option is not None:
118125
cli_args.extend(["--config-option", str(config_option)])
119126

120-
return run(args=cli_args, **kwargs)
127+
return run(
128+
args=cli_args,
129+
check_returncode=True if check_returncode is None else check_returncode,
130+
**kwargs,
131+
)
121132

122133
def checkout(
123134
self,
@@ -127,6 +138,15 @@ def checkout(
127138
force: Optional[bool] = None,
128139
ignore_externals: Optional[bool] = None,
129140
depth: DepthLiteral = None,
141+
quiet: Optional[bool] = None,
142+
username: Optional[str] = None,
143+
password: Optional[str] = None,
144+
no_auth_cache: Optional[bool] = None,
145+
non_interactive: Optional[bool] = True,
146+
trust_server_cert: Optional[bool] = None,
147+
# Special behavior
148+
make_parents: Optional[bool] = True,
149+
check_returncode: Optional[bool] = False,
130150
) -> str:
131151
"""Check out a working copy from an SVN repo.
132152
@@ -144,6 +164,10 @@ def checkout(
144164
ignore externals definitions
145165
depth :
146166
Sparse checkout support, Optional
167+
make_parents : bool, default: ``True``
168+
Creates checkout directory (`:attr:`self.dir`) if it doesn't already exist.
169+
check_returncode : bool, default: True
170+
Passthrough to :meth:`Svn.run`
147171
148172
Examples
149173
--------
@@ -157,15 +181,28 @@ def checkout(
157181
local_flags: list[str] = [url, str(self.dir)]
158182

159183
if revision is not None:
160-
local_flags.append(f"--revision={revision}")
184+
local_flags.extend(["--revision", revision])
161185
if depth is not None:
162-
local_flags.append(depth)
186+
local_flags.extend(["--depth", depth])
163187
if force is True:
164188
local_flags.append("--force")
165189
if ignore_externals is True:
166190
local_flags.append("--ignore-externals")
167191

168-
return self.run(["checkout", *local_flags], check_returncode=False)
192+
# libvcs special behavior
193+
if make_parents and not self.dir.exists():
194+
self.dir.mkdir(parents=True)
195+
196+
return self.run(
197+
["checkout", *local_flags],
198+
quiet=quiet,
199+
username=username,
200+
password=password,
201+
no_auth_cache=no_auth_cache,
202+
non_interactive=non_interactive,
203+
trust_server_cert=trust_server_cert,
204+
check_returncode=check_returncode,
205+
)
169206

170207
def add(
171208
self,
@@ -317,7 +354,7 @@ def blame(
317354
local_flags: list[str] = [str(target)]
318355

319356
if revision is not None:
320-
local_flags.append(f"--revision={revision}")
357+
local_flags.extend(["--revision", revision])
321358
if verbose is True:
322359
local_flags.append("--verbose")
323360
if use_merge_history is True:
@@ -764,7 +801,21 @@ def unlock(self, *args: Any, **kwargs: Any) -> str:
764801

765802
return self.run(["unlock", *local_flags])
766803

767-
def update(self, *args: Any, **kwargs: Any) -> str:
804+
def update(
805+
self,
806+
accept: Optional[str] = None,
807+
changelist: Optional[List[str]] = None,
808+
diff3_cmd: Optional[str] = None,
809+
editor_cmd: Optional[str] = None,
810+
force: Optional[bool] = None,
811+
ignore_externals: Optional[bool] = None,
812+
parents: Optional[bool] = None,
813+
quiet: Optional[bool] = None,
814+
revision: Optional[str] = None,
815+
set_depth: Optional[str] = None,
816+
*args: Any,
817+
**kwargs: Any,
818+
) -> str:
768819
"""
769820
Wraps `svn update
770821
<https://svnbook.red-bean.com/en/1.7/svn.ref.svn.c.update.html>`_ (up).
@@ -774,6 +825,25 @@ def update(self, *args: Any, **kwargs: Any) -> str:
774825
"""
775826
local_flags: list[str] = [*args]
776827

828+
if revision is not None:
829+
local_flags.extend(["--revision", revision])
830+
if diff3_cmd is not None:
831+
local_flags.extend(["--diff3-cmd", diff3_cmd])
832+
if editor_cmd is not None:
833+
local_flags.extend(["--editor-cmd", editor_cmd])
834+
if set_depth is not None:
835+
local_flags.extend(["--set-depth", set_depth])
836+
if changelist is not None:
837+
local_flags.extend(["--changelist", *changelist])
838+
if force is True:
839+
local_flags.append("--force")
840+
if quiet is True:
841+
local_flags.append("--quiet")
842+
if parents is True:
843+
local_flags.append("--parents")
844+
if ignore_externals is True:
845+
local_flags.append("--ignore-externals")
846+
777847
return self.run(["update", *local_flags])
778848

779849
def upgrade(self, *args: Any, **kwargs: Any) -> str:

0 commit comments

Comments
 (0)