Skip to content

GitSync: honor arbitrary clone depth#535

Merged
tony merged 4 commits into
masterfrom
feat/gitsync-depth
May 31, 2026
Merged

GitSync: honor arbitrary clone depth#535
tony merged 4 commits into
masterfrom
feat/gitsync-depth

Conversation

@tony
Copy link
Copy Markdown
Member

@tony tony commented May 31, 2026

Summary

Behavior

obtain() resolves the clone depth from a single precedence chain:

depth git_shallow git clone
N any --depth N
unset True --depth 1
unset False full clone

Design decisions

  • depth wins over git_shallow: a single source of truth when both are set, while an unset depth preserves the established git_shallow behavior for backward compatibility.
  • tls_verify scoped to the attribute fix: making the kwarg reachable unmasked three pre-existing bugs in the tls_verifygit -c http.sslVerify=... path (global-flag placement, --config vs -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_project kwargs typing: its **kwargs was annotated dict[Any, Any], mistyping every forwarded keyword; corrected to Any so the new typed params type-check.

Follow-up issues filed

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 a file:// remote
  • test_git_shallow_and_tls_verify_kwargs_are_honored — attributes are set; git_shallow drives a depth-1 clone
  • uv run ruff check . and uv run ruff format .
  • uv run mypy .
  • uv run py.test --reruns 0
  • just build-docs

…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
Copy link
Copy Markdown

codecov Bot commented May 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.51%. Comparing base (57b2971) to head (48ec1a5).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tony
Copy link
Copy Markdown
Member Author

tony commented May 31, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

@tony tony force-pushed the feat/gitsync-depth branch from 5575546 to 2502906 Compare May 31, 2026 13:39
tony added 3 commits May 31, 2026 08:49
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
@tony tony force-pushed the feat/gitsync-depth branch from 2502906 to 48ec1a5 Compare May 31, 2026 13:50
@tony tony merged commit 546b831 into master May 31, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant