-
Notifications
You must be signed in to change notification settings - Fork 39
Improve shallow clone #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3b89505
Clean up test output and error handling
marcosbento faa159b
Avoid setting git configuration globally
marcosbento a97c7ae
Correct shallowness check of submodules
marcosbento f21f118
Fail configuration when combining incorrect options with SHALLOW
marcosbento 1239746
Safeguard test scripts
marcosbento d5f30cd
Clarify information message
marcosbento 121330e
Add note regarding arguments forwarded between ecbuild_bundle/_git
marcosbento 6b8d401
Add tests to cover non-happy path scenarios
marcosbento df72cbb
Correct protocol.file.allow always setup
marcosbento File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| ECBUILD_PATH=${CMAKE_SOURCE_DIR}/bin | ||
| BINARY_TEST_DIR=${CMAKE_CURRENT_BINARY_DIR} | ||
|
|
||
| # | ||
| # Redirect HOME to a per-job temp directory so that every git process | ||
| # (including subprocesses spawned internally by git-submodule) reads a private | ||
| # ~/.gitconfig. This avoids lock contention on the real ~/.gitconfig when | ||
| # parallel CI jobs run, and works on all git versions. | ||
| # | ||
| # GIT_CONFIG_GLOBAL (requires git >= 2.32) and GIT_CONFIG_COUNT (not forwarded | ||
| # by git-submodule to its child processes) are not viable alternatives here. | ||
| # | ||
| # Required on git >= 2.38.1 and on distros that have backported CVE-2022-39253 | ||
| # (e.g. Debian 11's git 2.30.2). | ||
| # | ||
| _tmp_home=$(mktemp -d) | ||
| export HOME="${_tmp_home}" | ||
| trap 'rm -rf "${_tmp_home}"' EXIT | ||
| pushd "${HOME}" > /dev/null | ||
| git config --global protocol.file.allow always | ||
| git config --global user.name "Test User" | ||
| git config --global user.email "test@user" | ||
| popd > /dev/null | ||
|
|
||
| # Add ecbuild to path | ||
| export PATH=$ECBUILD_PATH:$PATH | ||
|
|
||
| # ---- cleanup ----------------------------------------- | ||
| [[ -n "${BINARY_TEST_DIR}" ]] || { echo "BINARY_TEST_DIR is not set"; exit 1; } | ||
| rm -rf "${BINARY_TEST_DIR}/workspace-invalid-noremote" | ||
|
|
||
| WORKSPACE="${BINARY_TEST_DIR}/workspace-invalid-noremote" | ||
| BUNDLE_DIR="${WORKSPACE}/bundle" | ||
|
|
||
| # ---- create bundle: SHALLOW + NOREMOTE (invalid combination) - | ||
| # ecbuild_critical fires before any git operation, so the URL need not exist. | ||
| mkdir -p "${BUNDLE_DIR}" | ||
| cat > "${BUNDLE_DIR}/CMakeLists.txt" <<EOF | ||
| cmake_minimum_required(VERSION 3.18 FATAL_ERROR) | ||
| find_package( ecbuild 3.12 REQUIRED HINTS ${CMAKE_SOURCE_DIR} ) | ||
| project( umbrella-bundle LANGUAGES NONE ) | ||
| ecbuild_bundle_initialize() | ||
| ecbuild_bundle( | ||
| PROJECT umbrella | ||
| GIT "file:///does-not-need-to-exist.git" | ||
| BRANCH main | ||
| SHALLOW | ||
| NOREMOTE | ||
| ) | ||
| ecbuild_bundle_finalize() | ||
| EOF | ||
|
|
||
| cat > "${BUNDLE_DIR}/VERSION" <<EOF | ||
| 0.0.1 | ||
| EOF | ||
|
|
||
| # ---- configure should FAIL with a clear error message -------- | ||
| mkdir -p "${WORKSPACE}/build" | ||
| cd "${WORKSPACE}/build" | ||
|
|
||
| set +e | ||
| output=$( ecbuild --prefix="$(pwd)/install" -- "${BUNDLE_DIR}" 2>&1 ) | ||
| cmake_status=$? | ||
| set -e | ||
|
|
||
| if [[ "${cmake_status}" -eq 0 ]]; then | ||
| echo "cmake configure should have failed for SHALLOW+NOREMOTE but succeeded: FAIL" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if echo "${output}" | grep -q "Cannot pass both NOREMOTE and SHALLOW"; then | ||
| echo "SHALLOW+NOREMOTE correctly rejected: PASS" | ||
| else | ||
| echo "cmake failed but expected error message not found: FAIL" | ||
| echo "${output}" | ||
| exit 1 | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| ECBUILD_PATH=${CMAKE_SOURCE_DIR}/bin | ||
| BINARY_TEST_DIR=${CMAKE_CURRENT_BINARY_DIR} | ||
|
|
||
| # | ||
| # Redirect HOME to a per-job temp directory so that every git process | ||
| # (including subprocesses spawned internally by git-submodule) reads a private | ||
| # ~/.gitconfig. This avoids lock contention on the real ~/.gitconfig when | ||
| # parallel CI jobs run, and works on all git versions. | ||
| # | ||
| # GIT_CONFIG_GLOBAL (requires git >= 2.32) and GIT_CONFIG_COUNT (not forwarded | ||
| # by git-submodule to its child processes) are not viable alternatives here. | ||
| # | ||
| # Required on git >= 2.38.1 and on distros that have backported CVE-2022-39253 | ||
| # (e.g. Debian 11's git 2.30.2). | ||
| # | ||
| _tmp_home=$(mktemp -d) | ||
| export HOME="${_tmp_home}" | ||
| trap 'rm -rf "${_tmp_home}"' EXIT | ||
| pushd "${HOME}" > /dev/null | ||
| git config --global protocol.file.allow always | ||
| git config --global user.name "Test User" | ||
| git config --global user.email "test@user" | ||
| popd > /dev/null | ||
|
|
||
| # Add ecbuild to path | ||
| export PATH=$ECBUILD_PATH:$PATH | ||
|
|
||
| # ---- cleanup ----------------------------------------- | ||
| [[ -n "${BINARY_TEST_DIR}" ]] || { echo "BINARY_TEST_DIR is not set"; exit 1; } | ||
| rm -rf "${BINARY_TEST_DIR}/workspace-invalid-update" | ||
|
|
||
| WORKSPACE="${BINARY_TEST_DIR}/workspace-invalid-update" | ||
| BUNDLE_DIR="${WORKSPACE}/bundle" | ||
|
|
||
| # ---- create bundle: SHALLOW + UPDATE (invalid combination) --- | ||
| # ecbuild_critical fires before any git operation, so the URL need not exist. | ||
| mkdir -p "${BUNDLE_DIR}" | ||
| cat > "${BUNDLE_DIR}/CMakeLists.txt" <<EOF | ||
| cmake_minimum_required(VERSION 3.18 FATAL_ERROR) | ||
| find_package( ecbuild 3.12 REQUIRED HINTS ${CMAKE_SOURCE_DIR} ) | ||
| project( umbrella-bundle LANGUAGES NONE ) | ||
| ecbuild_bundle_initialize() | ||
| ecbuild_bundle( | ||
| PROJECT umbrella | ||
| GIT "file:///does-not-need-to-exist.git" | ||
| BRANCH main | ||
| SHALLOW | ||
| UPDATE | ||
| ) | ||
| ecbuild_bundle_finalize() | ||
| EOF | ||
|
|
||
| cat > "${BUNDLE_DIR}/VERSION" <<EOF | ||
| 0.0.1 | ||
| EOF | ||
|
|
||
| # ---- configure should FAIL with a clear error message -------- | ||
| mkdir -p "${WORKSPACE}/build" | ||
| cd "${WORKSPACE}/build" | ||
|
|
||
| set +e | ||
| output=$( ecbuild --prefix="$(pwd)/install" -- "${BUNDLE_DIR}" 2>&1 ) | ||
| cmake_status=$? | ||
| set -e | ||
|
|
||
| if [[ "${cmake_status}" -eq 0 ]]; then | ||
| echo "cmake configure should have failed for SHALLOW+UPDATE but succeeded: FAIL" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if echo "${output}" | grep -q "Cannot pass both UPDATE and SHALLOW"; then | ||
| echo "SHALLOW+UPDATE correctly rejected: PASS" | ||
| else | ||
| echo "cmake failed but expected error message not found: FAIL" | ||
| echo "${output}" | ||
| exit 1 | ||
| fi |
96 changes: 96 additions & 0 deletions
96
tests/ecbuild_bundle_shallow/run-test-shallow-no-recursive.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| ECBUILD_PATH=${CMAKE_SOURCE_DIR}/bin | ||
| SOURCE_TEST_DIR=${CMAKE_CURRENT_SOURCE_DIR} | ||
| BINARY_TEST_DIR=${CMAKE_CURRENT_BINARY_DIR} | ||
|
|
||
| # | ||
| # Redirect HOME to a per-job temp directory so that every git process | ||
| # (including subprocesses spawned internally by git-submodule) reads a private | ||
| # ~/.gitconfig. This avoids lock contention on the real ~/.gitconfig when | ||
| # parallel CI jobs run, and works on all git versions. | ||
| # | ||
| # GIT_CONFIG_GLOBAL (requires git >= 2.32) and GIT_CONFIG_COUNT (not forwarded | ||
| # by git-submodule to its child processes) are not viable alternatives here. | ||
| # | ||
| # Required on git >= 2.38.1 and on distros that have backported CVE-2022-39253 | ||
| # (e.g. Debian 11's git 2.30.2). | ||
| # | ||
| _tmp_home=$(mktemp -d) | ||
| export HOME="${_tmp_home}" | ||
| trap 'rm -rf "${_tmp_home}"' EXIT | ||
| pushd "${HOME}" > /dev/null | ||
| git config --global protocol.file.allow always | ||
| git config --global user.name "Test User" | ||
| git config --global user.email "test@user" | ||
| popd > /dev/null | ||
|
|
||
| # Add ecbuild to path | ||
| export PATH=$ECBUILD_PATH:$PATH | ||
|
|
||
| # ---- cleanup ----------------------------------------- | ||
| [[ -n "${BINARY_TEST_DIR}" ]] || { echo "BINARY_TEST_DIR is not set"; exit 1; } | ||
| rm -rf "${BINARY_TEST_DIR}/workspace-shallow-only" | ||
|
|
||
| WORKSPACE="${BINARY_TEST_DIR}/workspace-shallow-only" | ||
| BUNDLE_DIR="${WORKSPACE}/bundle" | ||
|
|
||
| # ---- setup umbrella project (with submodules) -------- | ||
| cd "${BINARY_TEST_DIR}" | ||
| bash "${SOURCE_TEST_DIR}/setup-umbrella-project.sh" "${WORKSPACE}/projects" | ||
|
|
||
| BARE_DIR="${WORKSPACE}/bare-repos" | ||
| UMBRELLA_GIT="file://${BARE_DIR}/umbrella.git" | ||
|
|
||
| # ---- create bundle: SHALLOW only (no RECURSIVE) ------ | ||
| mkdir -p "${BUNDLE_DIR}" | ||
| cat > "${BUNDLE_DIR}/CMakeLists.txt" <<EOF | ||
| cmake_minimum_required(VERSION 3.18 FATAL_ERROR) | ||
| find_package( ecbuild 3.12 REQUIRED HINTS ${CMAKE_SOURCE_DIR} ) | ||
| project( umbrella-bundle LANGUAGES NONE ) | ||
| ecbuild_bundle_initialize() | ||
| ecbuild_bundle( | ||
| PROJECT umbrella | ||
| GIT "${UMBRELLA_GIT}" | ||
| BRANCH main | ||
| SHALLOW | ||
| ) | ||
| ecbuild_bundle_finalize() | ||
| EOF | ||
|
|
||
| cat > "${BUNDLE_DIR}/VERSION" <<EOF | ||
| 0.0.1 | ||
| EOF | ||
|
|
||
| # ---- configure umbrella bundle ----------------------- | ||
| mkdir -p "${WORKSPACE}/build" | ||
| cd "${WORKSPACE}/build" | ||
| ecbuild --prefix="$(pwd)/install" -- "${BUNDLE_DIR}" | ||
|
|
||
| # ---- check: umbrella is shallow ---------------------- | ||
| PASS=1 | ||
|
|
||
| cd "${BUNDLE_DIR}/umbrella" | ||
| if [[ "$(git rev-parse --is-shallow-repository)" != "true" ]]; then | ||
| echo "Umbrella is not shallow: FAIL" | ||
| PASS=0 | ||
| else | ||
| echo "Umbrella is shallow: PASS" | ||
| fi | ||
|
|
||
| # ---- check: submodules are NOT initialised ----------- | ||
| # Without RECURSIVE, ecbuild_git skips the submodule update step; the | ||
| # submodule directories should exist (as tracked gitlinks) but must not | ||
| # contain an initialised git repo (.git file/dir created by submodule init). | ||
| for sub in alpha beta gamma; do | ||
| if [[ -e "${BUNDLE_DIR}/umbrella/${sub}/.git" ]]; then | ||
| echo "Submodule ${sub} is initialised but RECURSIVE was not requested: FAIL" | ||
| PASS=0 | ||
| else | ||
| echo "Submodule ${sub} is not initialised: PASS" | ||
| fi | ||
| done | ||
|
|
||
| exit $(( 1 - PASS )) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ecbuild_critical fails? if yes, this changes the behavior, not just a log change as in PR desc. if it's intentional, it's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi.
I was just following the documentation above, which stated:
SHALLOW is not switchable and will fail if UPDATE is requested on an existing shallow clone.Given the inconsistency between implementation and documentation, I decided to err on the side of caution and fail clearly and as early as possible.