GitSync: honor arbitrary clone depth#535
Merged
Merged
Conversation
…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
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #535 +/- ##
==========================================
+ Coverage 58.23% 58.51% +0.27%
==========================================
Files 40 40
Lines 6489 6523 +34
Branches 1098 1099 +1
==========================================
+ Hits 3779 3817 +38
+ Misses 2177 2176 -1
+ Partials 533 530 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
Author
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
why: GitSync could express shallow-vs-full but not a numeric clone depth. The lower-level Git.clone() already accepted any `--depth N`, but obtain() hardcoded `depth=1 if self.git_shallow else None`, so downstream tools (e.g. vcspull) could only persist a boolean shallow flag rather than an arbitrary depth. Implements proposal points 1-2 of issue #531. what: - Add a `depth: int | None = None` keyword-only parameter to GitSync.__init__, stored as `self.depth`, alongside the existing git_shallow/tls_verify controls. - Resolve the clone depth in obtain() through an explicit precedence chain instead of the hardcoded ternary: * an explicit `depth` wins -> `git clone --depth <depth>`, * otherwise `git_shallow=True` keeps the prior depth-1 behavior, * otherwise the clone is full (`depth=None`). An unset `depth` reproduces the previous behavior exactly, so existing callers and the git_shallow path are unaffected. - Document `depth` in the GitSync docstring (takes precedence over git_shallow; default None means a full clone). - Record the deferred update-time deepen/unshallow (proposal point 3) as a `.. todo::` in update_repo(), pointing at follow-up issue #532 and naming the two git edges a future implementation must handle: `git fetch --depth N` truncates a full checkout to shallow, and `git fetch --unshallow` against a complete repo is a fatal error (guard with `git rev-parse --is-shallow-repository`). Refs #531
why: Lock in the depth-selection behavior of GitSync.obtain(): an
explicit `depth` must win over `git_shallow`, `git_shallow` must still
clone at depth 1, and the default must remain a full clone. Without
coverage the precedence chain and the resulting on-disk shallow state
could regress silently.
what:
- Add `test_obtain_honors_clone_depth`, parametrized with a
`typing.NamedTuple` (DepthFixture) plus a `test_id` for ids, over
four cases:
* full-clone (no kwargs) -> 6 commits, not shallow,
* git_shallow=True -> 1 commit, shallow,
* depth=3 -> 3 commits, shallow,
* depth=2 + git_shallow=True -> 2 commits, shallow
(depth overrides git_shallow).
- Build a 6-commit remote with create_git_remote_repo() and
git_commit_envvars, run obtain(), then assert
`git rev-list --count HEAD` and `git rev-parse
--is-shallow-repository` against each case's expectations.
- Clone over the remote's file:// URI (remote_repo.as_uri()): git
ignores `--depth` for local-path clones, so the file transport is
required for the depth assertions to be meaningful. This invariant is
documented in the test docstring.
- Add the `os` import (for the commit env) and the GitCommitEnvVars
type import the new test relies on.
Refs #531
why: Surface the new GitSync `depth` capability in the unreleased 0.42.x changelog so users discover they can request `--depth N` and persist a numeric depth, not just a boolean shallow flag. what: - Add a `### What's new` deliverable under the 0.42.x (unreleased) block: "#### GitSync honors an arbitrary clone depth (#531)". - Describe the new `depth` keyword argument, that obtain() forwards it to `git clone --depth N`, that an unset `depth` preserves the prior behavior (git_shallow -> depth 1, else full), and the downstream benefit of persisting/applying a numeric depth. - Link the affected API with MyST roles ({class} GitSync, {meth} obtain) per the changelog conventions. Refs #531
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
depthkeyword argument toGitSync;obtain()forwards it togit clone --depth N. Leaving it unset preserves today's behavior, so existing callers are unaffected. This lets downstream tools persist and apply a numeric shallow depth instead of only a boolean shallow flag. Addresses GitSync: honor arbitrary clone depth on sync, not just --depth 1 #531.git_shallow=Trueortls_verify=TruetoGitSyncnever set the attribute, so the nextobtain()raisedAttributeError. Both are now explicit keyword-only constructor arguments. This affected published releases.update_repo().. todo::with the git edges it must handle.Behavior
obtain()resolves the clone depth from a single precedence chain:depthgit_shallowgit cloneN--depth NTrue--depth 1FalseDesign decisions
depthwins overgit_shallow: a single source of truth when both are set, while an unsetdepthpreserves the establishedgit_shallowbehavior for backward compatibility.tls_verifyscoped to the attribute fix: making the kwarg reachable unmasked three pre-existing bugs in thetls_verify→git -c http.sslVerify=...path (global-flag placement,--configvs-c, inverted semantics). Those are out of scope here and tracked in Git.run / GitSync: tls_verify config passthrough is broken (-c placement, --config vs -c, inverted sslVerify) #533; this PR wires up the attribute but deliberately does not exercise the broken clone path.create_projectkwargs typing: its**kwargswas annotateddict[Any, Any], mistyping every forwarded keyword; corrected toAnyso the new typed params type-check.Follow-up issues filed
tls_verify/config passthrough bugs (flag ordering,--configvs-c, invertedsslVerify)Git.fetch/Git.pulltypedepthasstr, inconsistent withGit.clone(int)Test plan
test_obtain_honors_clone_depth— parametrized over full /git_shallow/depth=N/ depth-overrides-git_shallow; asserts commit count and shallow state against afile://remotetest_git_shallow_and_tls_verify_kwargs_are_honored— attributes are set;git_shallowdrives a depth-1 cloneuv run ruff check .anduv run ruff format .uv run mypy .uv run py.test --reruns 0just build-docs