diff --git a/versioncontrol/git.groovy b/versioncontrol/git.groovy index 1bf9cd1..ccbd458 100644 --- a/versioncontrol/git.groovy +++ b/versioncontrol/git.groovy @@ -227,6 +227,25 @@ def setlfsfetchinclude(String targetDir, ArrayList sparseitemlist) { } } +def gitsparserestore(String targetDir) { + echo "Clean out full fetch; Force a sparse fetch" + dir(targetDir) { + if (isUnix()) { + sh """ + git rm -rf . + git clean -fxd + git reset --hard + """ + } else { + bat """ + git rm -rf . + git clean -fxd + git reset --hard + """ + } + } + } + def gitCheckoutAlt(String gitURL, String revision, String targetDir, String repoRootSuffix = "", int cloneDepth = 1, boolean shallowClone = true, ArrayList sparseitemlist = new ArrayList()) { echo "Performing alternative checkout" def String reporootpath = lfsinstallandreporoot(gitURL) @@ -236,6 +255,9 @@ def gitCheckoutAlt(String gitURL, String revision, String targetDir, String repo setlfsfetchinclude(targetDir, sparseitemlist) } docheckout(gitURL, revision, cloneDepth, reporootpath, shallowClone, targetDir, sparseitemlist) + if (!sparseitemlist.isEmpty()) { + gitsparserestore(targetDir) + } } def checkRepoExists(String gitURL) {