Skip to content

[ExternalProject] GIT_SHALLOW is not shallow enough

Hi,

the use-case of "GIT_SHALLOW 1" is to optimize the cloning to download as little as possible. But the ExternalProject_Add implementation does this:

  if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.10)
    set(git_clone_shallow_options "--depth 1 --no-single-branch")
  else()
    set(git_clone_shallow_options "--depth 1")
  endif()

For some git versions the --no-single-branch option is passed, and this option will cause all branch HEAD's to be downloaded, instead of just the branch/tag/commit that one wanted to download. This causes a performance problem if a branch exists purely to prune the master branch.

My question is:

Why is this option passed for some git --versions?

Is there a way we can support single-sha downloads with CMake?

Should the documentation be updated to reflect that GIT_SHALLOW does not just download a single revision?

CMake documentation:

GIT_SHALLOW When this option is enabled, the git clone operation will be given the --depth 1 option. This performs a shallow clone, which avoids downloading the whole history and instead retrieves just the commit denoted by the GIT_TAG option.

git documentation:

 --depth <depth>
     Create a shallow clone with a history truncated to the
     specified number of commits. Implies --single-branch
     unless --no-single-branch is given to fetch the
     histories near the tips of all branches. If you want to
     clone submodules shallowly, also pass
     --shallow-submodules.

 --[no-]single-branch
     Clone only the history leading to the tip of a single
     branch, either specified by the --branch option or the
     primary branch remote’s HEAD points at. Further fetches
     into the resulting repository will only update the
     remote-tracking branch for the branch this option was
     used for the initial cloning. If the HEAD at the remote
     did not point at any branch when --single-branch clone
     was made, no remote-tracking branch is created.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information