Skip to content

Commit 699ade0

Browse files
committed
Use treeless clone to do a 'shallow' clone preserving metadata for version.py
1 parent bc0e6be commit 699ade0

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

bootstrap-salt.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,21 +2097,19 @@ __git_clone_and_checkout() {
20972097
fi
20982098

20992099
if [ "$__SHALLOW_CLONE" -eq $BS_TRUE ]; then
2100-
# Let's try shallow cloning to speed up.
2101-
# Test for "--single-branch" option introduced in git 1.7.10, the minimal version of git where the shallow
2100+
# Let's try 'treeless' cloning to speed up. Treeless cloning omits trees and blobs ('files')
2101+
# but includes metadata (commit history, tags, branches etc.
2102+
# Test for "--filter" option introduced in git 2.19, the minimal version of git where the treeless
21022103
# cloning we need actually works
2103-
if [ "$(git clone 2>&1 | grep 'single-branch')" != "" ]; then
2104-
# The "--single-branch" option is supported, attempt shallow cloning
2104+
if [ "$(git clone 2>&1 | grep 'filter')" != "" ]; then
2105+
# The "--filter" option is supported, attempt treeless cloning
21052106
echoinfo "Attempting to shallow clone $GIT_REV from Salt's repository ${_SALT_REPO_URL}"
2106-
## Shallow cloning is resulting in the wrong version of Salt, even with a depth of 5
2107-
## getting 3007.0+0na.246d066 when it should be 3007.1+410.g246d066457, disabling for now
2108-
## if git clone --depth 1 --branch "$GIT_REV" "$_SALT_REPO_URL" "$__SALT_CHECKOUT_REPONAME"; then
2109-
echodebug "git command, git clone --branch $GIT_REV $_SALT_REPO_URL $__SALT_CHECKOUT_REPONAME"
2110-
if git clone --branch "$GIT_REV" "$_SALT_REPO_URL" "$__SALT_CHECKOUT_REPONAME"; then
2107+
echodebug "git command, git clone --filter=tree:0 --branch $GIT_REV $_SALT_REPO_URL $__SALT_CHECKOUT_REPONAME"
2108+
if git clone --filter=tree:0 --branch "$GIT_REV" "$_SALT_REPO_URL" "$__SALT_CHECKOUT_REPONAME"; then
21112109
# shellcheck disable=SC2164
21122110
cd "${_SALT_GIT_CHECKOUT_DIR}"
21132111
__SHALLOW_CLONE=$BS_TRUE
2114-
echoinfo "shallow path (disabled shallow) git cloned $GIT_REV, version $(python3 salt/version.py)"
2112+
echoinfo "shallow path git cloned $GIT_REV, version $(python3 salt/version.py)"
21152113
else
21162114
# Shallow clone above failed(missing upstream tags???), let's resume the old behaviour.
21172115
echowarn "Failed to shallow clone."

0 commit comments

Comments
 (0)