Skip to content

Commit 87953b6

Browse files
committed
sync/git(fix[GitSync]): Honor git_shallow and tls_verify constructor args
why: Passing git_shallow=True or tls_verify=True never set the attribute, so the next obtain() raised AttributeError. The implicit **kwargs-to-__dict__ assignment that once populated them was removed in v0.4.4, leaving the `if "x" not in kwargs` blocks to set only the default-False case. what: - Accept git_shallow and tls_verify as explicit keyword-only params on GitSync.__init__ and assign them directly - Type create_project's **kwargs as t.Any (was dict[Any, Any], which mis-typed every forwarded keyword) so the now-typed params type-check - Document git_shallow in the GitSync docstring - Add a regression test: attributes are set, and git_shallow drives a shallow (depth-1) clone - CHANGES: Fixes entry
1 parent 57b2971 commit 87953b6

4 files changed

Lines changed: 56 additions & 9 deletions

File tree

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ $ uv add libvcs --prerelease allow
2020
_Notes on the upcoming release will go here._
2121
<!-- END PLACEHOLDER - ADD NEW CHANGELOG ENTRIES BELOW THIS LINE -->
2222

23+
### Fixes
24+
25+
#### GitSync honors `git_shallow` and `tls_verify` constructor arguments (#531)
26+
27+
Passing `git_shallow=True` or `tls_verify=True` to {class}`~libvcs.sync.git.GitSync` left the matching attribute unset, so the next {meth}`~libvcs.sync.git.GitSync.obtain` raised `AttributeError`. Both are now accepted as keyword-only constructor arguments and applied when cloning.
28+
2329
## libvcs 0.41.0 (2026-05-10)
2430

2531
libvcs 0.41.0 is a pytest-plugin compatibility release. It renames libvcs's Git and Mercurial config fixtures so the plugin no longer occupies fixture names used by third-party pytest plugins, and it keeps the docs stack aligned with the current gp-sphinx theme pipeline.

src/libvcs/_internal/shortcuts.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def create_project(
3838
path: StrPath,
3939
vcs: t.Literal["git"],
4040
progress_callback: ProgressCallbackProtocol | None = None,
41-
**kwargs: dict[t.Any, t.Any],
41+
**kwargs: t.Any,
4242
) -> GitSync: ...
4343

4444

@@ -49,7 +49,7 @@ def create_project(
4949
path: StrPath,
5050
vcs: t.Literal["svn"],
5151
progress_callback: ProgressCallbackProtocol | None = None,
52-
**kwargs: dict[t.Any, t.Any],
52+
**kwargs: t.Any,
5353
) -> SvnSync: ...
5454

5555

@@ -60,7 +60,7 @@ def create_project(
6060
path: StrPath,
6161
vcs: t.Literal["hg"],
6262
progress_callback: ProgressCallbackProtocol | None = ...,
63-
**kwargs: dict[t.Any, t.Any],
63+
**kwargs: t.Any,
6464
) -> HgSync: ...
6565

6666

@@ -71,7 +71,7 @@ def create_project(
7171
path: StrPath,
7272
vcs: None = None,
7373
progress_callback: ProgressCallbackProtocol | None = None,
74-
**kwargs: dict[t.Any, t.Any],
74+
**kwargs: t.Any,
7575
) -> GitSync | HgSync | SvnSync: ...
7676

7777

@@ -81,7 +81,7 @@ def create_project(
8181
path: StrPath,
8282
vcs: VCSLiteral | None = None,
8383
progress_callback: ProgressCallbackProtocol | None = None,
84-
**kwargs: dict[t.Any, t.Any],
84+
**kwargs: t.Any,
8585
) -> GitSync | HgSync | SvnSync:
8686
r"""Return an object representation of a VCS repository.
8787

src/libvcs/sync/git.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ def __init__(
211211
url: str,
212212
path: StrPath,
213213
remotes: GitRemotesArgs = None,
214+
git_shallow: bool = False,
215+
tls_verify: bool = False,
214216
**kwargs: t.Any,
215217
) -> None:
216218
"""Local git repository.
@@ -220,6 +222,10 @@ def __init__(
220222
url : str
221223
URL of repo
222224
225+
git_shallow : bool
226+
Clone with history truncated to the latest commit (``--depth 1``,
227+
default False)
228+
223229
tls_verify : bool
224230
Should certificate for https be checked (default False)
225231
@@ -258,10 +264,8 @@ def __init__(
258264
}
259265
)
260266
"""
261-
if "git_shallow" not in kwargs:
262-
self.git_shallow = False
263-
if "tls_verify" not in kwargs:
264-
self.tls_verify = False
267+
self.git_shallow = git_shallow
268+
self.tls_verify = tls_verify
265269

266270
self._remotes: GitSyncRemoteDict
267271

tests/sync/test_git.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,43 @@ def test_repo_git_obtain_full(
120120
assert (tmp_path / "myrepo").exists()
121121

122122

123+
def test_git_shallow_and_tls_verify_kwargs_are_honored(
124+
tmp_path: pathlib.Path,
125+
git_remote_repo: pathlib.Path,
126+
) -> None:
127+
"""``git_shallow`` and ``tls_verify`` populate their attributes.
128+
129+
Regression: each kwarg previously left its attribute unset, so the next
130+
``obtain()`` raised ``AttributeError``.
131+
"""
132+
# tls_verify reaches the attribute. Its clone-time ``config`` wiring is
133+
# broken independently of this fix and tracked separately, so we don't
134+
# drive a clone with it here.
135+
assert (
136+
GitSync(
137+
url=git_remote_repo.as_uri(),
138+
path=tmp_path / "tls",
139+
tls_verify=True,
140+
).tls_verify
141+
is True
142+
)
143+
144+
# git_shallow drives a depth-1 (shallow) clone in obtain().
145+
git_repo = GitSync(
146+
url=git_remote_repo.as_uri(),
147+
path=tmp_path / "myrepo",
148+
git_shallow=True,
149+
)
150+
assert git_repo.git_shallow is True
151+
git_repo.obtain()
152+
153+
is_shallow = run(
154+
["git", "rev-parse", "--is-shallow-repository"],
155+
cwd=tmp_path / "myrepo",
156+
)
157+
assert is_shallow == "true"
158+
159+
123160
@pytest.mark.parametrize(
124161
# Postpone evaluation of options so fixture variables can interpolate
125162
("constructor", "lazy_constructor_options"),

0 commit comments

Comments
 (0)