8000 feat(cmd[git]): Improve config param by using dict · vcs-python/libvcs@36db703 · GitHub
[go: up one dir, main page]

Skip to content

Commit 36db703

Browse files
committed
feat(cmd[git]): Improve config param by using dict
1 parent ba4c53f commit 36db703

File tree

1 file changed

+20
-4
lines changed
  • src/libvcs/cmd

1 file changed

+20
-4
lines changed

src/libvcs/cmd/git.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def run(
5858
noglob_pathspecs: Optional[bool] = None,
5959
icase_pathspecs: Optional[bool] = None,
6060
no_optional_locks: Optional[bool] = None,
61-
config: Optional[str] = None,
61+
config: Optional[dict[str, Any]] = None,
6262
config_env: Optional[str] = None,
6363
**kwargs: Any,
6464
) -> str:
@@ -156,6 +156,18 @@ def run(
156156
C = [C]
157157
C = [str(c) for c in C]
158158
cli_args.extend(["-C", C])
159+
if config is not None:
160+
assert isinstance(config, dict)
161+
162+
def stringify(v: Any) -> str:
163+
if isinstance(v, bool):
164+
return "true" if True else "false"
165+
elif not isinstance(v, str):
166+
return str(v)
167+
return v
168+
169+
for k, v in config.items():
170+
cli_args.extend(["--config", f"{k}={stringify(v)}"])
159171
if git_dir is not None:
160172
cli_args.extend(["--git-dir", str(git_dir)])
161173
if work_tree is not None:
@@ -189,7 +201,7 @@ def clone(
189201
url: str,
190202
separate_git_dir: Optional[StrOrBytesPath] = None,
191203
template: Optional[str] = None,
192-
depth: Optional[str] = None,
204+
depth: Optional[int] = None,
193205
branch: Optional[str] = None,
194206
origin: Optional[str] = None,
195207
upload_pack: Optional[str] = None,
@@ -216,6 +228,8 @@ def clone(
216228
no_remote_submodules: Optional[bool] = None,
217229
verbose: Optional[bool] = None,
218230
quiet: Optional[bool] = None,
231+
# Pass-through to run
232+
config: Optional[dict[str, Any]] = None,
219233
# Special behavior
220234
make_parents: Optional[bool] = True,
221235
**kwargs: Any,
@@ -254,7 +268,7 @@ def clone(
254268
if (filter := kwargs.pop("filter", None)) is not None:
255269
local_flags.append(f"--filter={filter}")
256270
if depth is not None:
257-
local_flags.extend(["--depth", depth])
271+
local_flags.extend(["--depth", str(depth)])
258272
if branch is not None:
259273
local_flags.extend(["--branch", branch])
260274
if origin is not None:
@@ -308,7 +322,9 @@ def clone(
308322
if make_parents and not self.dir.exists():
309323
self.dir.mkdir(parents=True)
310324
return self.run(
311-
["clone", *local_flags, "--", *required_flags], check_returncode=False
325+
["clone", *local_flags, "--", *required_flags],
326+
config=config,
327+
check_returncode=False,
312328
)
313329

314330
def fetch(

0 commit comments

Comments
 (0)
0