Skip to content

UpdateSubmodules().WithDepth(n) makes a full clone when the submodule URL is a local path #279

Open

Description

@matt-edmondson

What's wrong

IGitSubmoduleUpdateBuilder.WithDepth is documented as "Fetches only this many commits of history for a submodule being cloned" (GitIntegration/Builders/GitSubmoduleUpdateBuilder.cs:75-79) and emits --depth <n> (:182). This is the same git behaviour that #251 / #275 fixed for Clone().

When the submodule's URL is a plain local path, git's internal clone ignores the depth. It prints warning: --depth is ignored in local clones; use file:// instead., exits 0, and leaves a full clone. #251 flagged this possibility ("UpdateSubmodules().WithDepth may have the same problem … That hasn't been checked"), but #275 did not change this builder.

You only hit this where git may clone local-path submodules, i.e. with protocol.file.allow=always; since git 2.38.1, git refuses such clones otherwise. That setting is common wherever submodules point at local fixture repositories. This repo's own GitSubmoduleTests sets it (GitIntegration.Test/Integration/GitSubmoduleTests.cs:79).

Reproduction (git 2.43)

super has submodule 'sub' with url /tmp/smx/sub (3 commits); git clone super clone
git -c protocol.file.allow=always submodule update --init --depth 1
  -> warning: --depth is ignored in local clones; use file:// instead.  (exit 0)
git -C sub rev-parse --is-shallow-repository -> false ; rev-list --count HEAD -> 3

Suggested fix

submodule update has no --no-local, so there are two options:

  • Rewrite local paths to file:// URLs. Adding -c url."file:///".insteadOf=/ makes the same command produce a shallow clone (verified: is-shallow-repository reports true). This only covers POSIX absolute paths; Windows drive paths would need their own mapping.
  • Document the limit. Add a note to WithDepth's remarks that it has no effect for local-path submodule URLs and that callers should use file:// URLs.

Acceptance criteria

  • An integration test uses a local-path submodule, sets protocol.file.allow=always, and runs UpdateSubmodules().Initialize().WithDepth(1).
  • If the URL rewrite is chosen, the test asserts the submodule is shallow. If the documentation route is chosen, the WithDepth remarks state the limit.

Activity

  1. matt-edmondson commented on Oct 20, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions