Skip to content

fix(cmake): don't use GIT_SHALLOW when a dependency is pinned to a commit#2146

Merged
servantftransperfect merged 1 commit into
developfrom
fix/cmake-git-shallow-pinned-commit
Jun 26, 2026
Merged

fix(cmake): don't use GIT_SHALLOW when a dependency is pinned to a commit#2146
servantftransperfect merged 1 commit into
developfrom
fix/cmake-git-shallow-pinned-commit

Conversation

@predat

@predat predat commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Problem

av_add_cmake_dep (in src/cmake/Helpers.cmake) enabled GIT_SHALLOW TRUE
for every git dependency.

A shallow clone (git clone --depth 1) only fetches the tip of the remote's
default branch. When GIT_TAG is a commit hash that is not that tip, the
subsequent checkout fails:

fatal: unable to read tree <sha>
CMake Error: Failed to checkout tag: '<sha>'

The commit is not actually missing — it is fetchable — but the shallow clone
never downloads it, so the checkout cannot find it.

Impact

This breaks ALICEVISION_BUILD_DEPENDENCIES for any dependency pinned to a
commit that is not the default-branch tip. Concretely, the dependency build
fails on popsift and cctag. Dependencies pinned to a hash that happens
to be the default-branch tip only built by luck.

Dependencies referenced by a named branch/tag (v4.5.1, main, …) are
unaffected.

Fix

Enable GIT_SHALLOW only when GIT_TAG is a named branch/tag, not a raw
commit hash:

if(NOT _D_GIT_TAG MATCHES "^[0-9a-fA-F]+$")
    list(APPEND _D_SRC_ARGS GIT_SHALLOW TRUE)
endif()
  • Named refs keep the shallow-clone speedup.
  • Commit-pinned deps get a full clone and check out reliably.

Notes

Regression introduced in 634581fb4 ("modernize Docker/CMake infrastructure"),
which added the unconditional GIT_SHALLOW TRUE.

Verified by a full ALICEVISION_BUILD_DEPENDENCIES Docker build (Rocky 9 +
CUDA 12.1.1): with this change, popsift and cctag clone and build correctly,
and the whole dependency set builds to completion.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the CMake helper macro to conditionally enable shallow cloning only when the Git tag is not a commit hash, avoiding checkout failures. The feedback recommends quoting the variable in the CMake conditional check to prevent syntax errors if the variable is empty or contains special characters.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/cmake/Helpers.cmake Outdated
# défaut ; si GIT_TAG est un hash de commit qui n'en est pas le sommet,
# le checkout échoue ("unable to read tree"). On ne l'active donc que
# pour les tags/branches nommés, pas pour les commits épinglés.
if(NOT _D_GIT_TAG MATCHES "^[0-9a-fA-F]+$")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In CMake, it is highly recommended to quote variables in if conditions when using MATCHES. If _D_GIT_TAG is empty, undefined, or contains special characters (such as spaces, semicolons, or parentheses), an unquoted variable expansion can lead to syntax errors or unexpected behavior during the CMake configuration step. Quoting it as "${_D_GIT_TAG}" ensures it is always safely evaluated as a single string.

        if(NOT "${_D_GIT_TAG}" MATCHES "^[0-9a-fA-F]+$")

@predat predat force-pushed the fix/cmake-git-shallow-pinned-commit branch 3 times, most recently from 65c5371 to fbbd39d Compare June 25, 2026 13:56
@sonarqubecloud

Copy link
Copy Markdown

GIT_SHALLOW fetches only the default-branch tip, so a GIT_TAG that is a
commit hash not at that tip fails to check out ("unable to read tree").
This broke popsift and cctag. Enable GIT_SHALLOW only for named refs.

Regression introduced in 634581f.
@servantftransperfect servantftransperfect force-pushed the fix/cmake-git-shallow-pinned-commit branch from fbbd39d to 3596651 Compare June 26, 2026 06:44
@servantftransperfect servantftransperfect merged commit 1029c6b into develop Jun 26, 2026
2 of 6 checks passed
@servantftransperfect servantftransperfect deleted the fix/cmake-git-shallow-pinned-commit branch June 26, 2026 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants