Skip to content

fix(gix-protocol): only request deepen-relative in V0/V1 when relative deepening is asked for. - #3250

Open
sagi-qryptonite wants to merge 1 commit into
GitoxideLabs:mainfrom
sagi-qryptonite:fix-v1-deepen-relative
Open

sagi-qryptonite wants to merge 1 commit into
GitoxideLabs:mainfrom
sagi-qryptonite:fix-v1-deepen-relative

Conversation

@sagi-qryptonite

Copy link
Copy Markdown

This PR was written by Claude, an AI agent, through sagi-qryptonite's account. Everything below is my own account of the work.

Motivation

Found while reviewing #3248, which fixes shallow clones from Azure DevOps for a repository scanner built on gix. That scanner fetches with Shallow::DepthAtRemote(1). Against any V0/V1 server running stock git upload-pack, those depth-1 clones turned into silent full clones.

Root cause

Before protocol V2, deepen-relative is a capability. git fetch-pack adds it to the first want only for git fetch --deepen (fetch-pack.c). The deepen-relative argument line exists only in V2 (fetch-pack.c). Arguments got both of these wrong:

  1. Arguments::new() put every advertised V0/V1 capability on the first want, including deepen-relative. Stock git upload-pack advertises it, so every deepen N became relative to the client's current shallow boundary. A fresh clone has no boundary yet, so the server sends no shallow lines and the full history, and the clone silently isn't shallow. On a repository that is already shallow, DepthAtRemote(n) instead deepens by n beyond the existing boundary.
  2. Arguments::deepen_relative() pushed deepen-relative as a line. In V0/V1, receive_needs() dies on it with "expected to get object ID, not 'deepen-relative'" (upload-pack.c), so Shallow::Deepen fails.

V2 is not affected, and the e2e shallow tests (in gix/tests/gix/remote/fetch.rs) run their shallow cases with V2 only, which is why this went unnoticed.

Evidence

DepthAtRemote(1) clone of https://github.com/octocat/Hello-World (3 commits) with protocol.version=1:

request result
main want 7fd1a60… thin-pack side-band-64k ofs-delta shallow deepen-since deepen-not deepen-relative … 3 commits, no shallow file
this PR want 7fd1a60… thin-pack side-band-64k ofs-delta shallow deepen-since deepen-not … 1 commit, 1 shallow boundary

The same happens against a local git upload-pack (git 2.50.1). The server answers FLUSH, NAK without any shallow line and sends the full pack.

Change

  • Arguments::new() no longer puts deepen-relative on the first want, the same way it already treats include-tag.
  • Arguments::deepen_relative() adds it as a capability in V0/V1 (via add_feature()) and as an argument in V2. In V0/V1 it must therefore be called before the first want(), like use_include_tag(). fetch() already does that.

Tests

  • clone::blocking_io::from_non_shallow_then_deepen_then_deepen_since_to_unshallow now runs with protocol V1 and V2 against git upload-pack and expects the same shallow boundaries for both. Most of its diff is re-indentation for the loop, so it's easier to read with whitespace changes hidden. On main, the V1 run fails at its first assertion (is_shallow()). With only the first fix, it fails on Shallow::Deepen with Broken pipe as upload-pack dies.
  • fetch::arguments::v1::haves_and_wants_for_fetch_stateless now advertises deepen-relative and checks it isn't requested. haves_and_wants_for_fetch_stateful checks that deepen_relative() becomes a capability of the first want and not a line.
  • fetch::response::v1::arguments::all encoded the old request with the separate deepen-relative line. It now expects the capability instead.
  • cargo test -p gix-protocol passes with blocking-client and async-client. cargo check -p gix-protocol --no-default-features --features sha1 passes. cargo fmt --check passes, and cargo clippy reports nothing new.
  • cargo test -p gix --features blocking-network-client --test gix -- remote:: clone passes except fetch_and_checkout_honors_shared_repository_permissions, which fails the same way on main on macOS.

Note

This is independent of #3248. Both change the expected request in fetch::response::v1::arguments::all and the V1 stateless test in fetch/arguments.rs, so whichever lands second needs a small rebase. I'll do that.

…ive deepening is asked for.

Before protocol V2, `deepen-relative` is a capability that `git fetch-pack`
adds to the first `want` only for `git fetch --deepen`. It is not an argument
line (see `fetch-pack.c` and `receive_needs()` in `upload-pack.c`).

`Arguments` got both of these wrong:

- `Arguments::new()` put every advertised V0/V1 capability on the first `want`,
  so `deepen-relative` was requested whenever the server advertised it, which
  stock `git upload-pack` does. That made every `deepen` relative to the
  client's current shallow boundary. A shallow clone has no boundary yet, so
  the server sent no `shallow` lines and the whole history, which silently
  turned a `Shallow::DepthAtRemote(1)` clone into a full clone.
- `Arguments::deepen_relative()` pushed `deepen-relative` as its own line, which
  `git upload-pack` rejects with "expected to get object ID", so
  `Shallow::Deepen` failed over V0/V1.

Now `deepen-relative` isn't baked into the first `want` anymore, and
`deepen_relative()` adds it as a capability in V0/V1 and as an argument in V2.

`from_non_shallow_then_deepen_then_deepen_since_to_unshallow` now also runs
with protocol V1 against `git upload-pack` and expects the same shallow
boundaries as with V2.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T14:27:06.400047Z 9770c8e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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