@@ -679,6 +679,13 @@ class GithubScm extends Scm {
679679 `else export GIT_RECURSIVE_OPTION="--recursive"; fi`
680680 ) ;
681681
682+ // Set sparse option
683+ command . push (
684+ 'if [ ! -z "$GIT_SPARSE_CHECKOUT_PATH" ]; ' +
685+ `then export GIT_SPARSE_OPTION="--no-checkout";` +
686+ `else export GIT_SPARSE_OPTION=""; fi`
687+ ) ;
688+
682689 // Export environment variables
683690 command . push ( 'echo Exporting environment variables' ) ;
684691 // Use read-only clone type
@@ -766,13 +773,20 @@ class GithubScm extends Scm {
766773 `${
767774 'if [ ! -z $GIT_SHALLOW_CLONE ] && [ $GIT_SHALLOW_CLONE = false ]; ' +
768775 'then $SD_GIT_WRAPPER ' +
769- `"git clone $GIT_RECURSIVE_OPTION --quiet --progress --branch '${ escapedParentBranch } ' ` +
776+ `"git clone $GIT_SPARSE_OPTION $ GIT_RECURSIVE_OPTION --quiet --progress --branch '${ escapedParentBranch } ' ` +
770777 '$CONFIG_URL $SD_CONFIG_DIR"; '
771778 } ${ shallowCloneCmd } ` +
772- `$GIT_RECURSIVE_OPTION --quiet --progress --branch '${ escapedParentBranch } ' ` +
779+ `$GIT_SPARSE_OPTION $ GIT_RECURSIVE_OPTION --quiet --progress --branch '${ escapedParentBranch } ' ` +
773780 '$CONFIG_URL $SD_CONFIG_DIR"; fi'
774781 ) ;
775782
783+ // Sparse Checkout
784+ command . push (
785+ 'if [ ! -z "$GIT_SPARSE_CHECKOUT_PATH" ];' +
786+ 'then $SD_GIT_WRAPPER "git sparse-checkout set $GIT_SPARSE_CHECKOUT_PATH" && ' +
787+ '$SD_GIT_WRAPPER "git checkout"; fi'
788+ ) ;
789+
776790 // Reset to SHA
777791 command . push ( `$SD_GIT_WRAPPER "git -C $SD_CONFIG_DIR reset --hard ${ config . parentConfig . sha } --"` ) ;
778792 command . push ( `echo Reset external config repo to ${ config . parentConfig . sha } ` ) ;
@@ -826,13 +840,20 @@ class GithubScm extends Scm {
826840 `${
827841 'if [ ! -z $GIT_SHALLOW_CLONE ] && [ $GIT_SHALLOW_CLONE = false ]; ' +
828842 'then $SD_GIT_WRAPPER ' +
829- `"git clone $GIT_RECURSIVE_OPTION --quiet --progress --branch '${ doubleQuoteEscapedBranch } ' ` +
843+ `"git clone $GIT_SPARSE_OPTION $ GIT_RECURSIVE_OPTION --quiet --progress --branch '${ doubleQuoteEscapedBranch } ' ` +
830844 '$SCM_URL $SD_CHECKOUT_DIR_FINAL"; '
831845 } ${ shallowCloneCmd } ` +
832- `$GIT_RECURSIVE_OPTION --quiet --progress --branch '${ doubleQuoteEscapedBranch } ' ` +
846+ `$GIT_SPARSE_OPTION $ GIT_RECURSIVE_OPTION --quiet --progress --branch '${ doubleQuoteEscapedBranch } ' ` +
833847 '$SCM_URL $SD_CHECKOUT_DIR_FINAL"; fi'
834848 ) ;
835849
850+ // Sparse Checkout
851+ command . push (
852+ 'if [ ! -z "$GIT_SPARSE_CHECKOUT_PATH" ];' +
853+ 'then $SD_GIT_WRAPPER "git sparse-checkout set $GIT_SPARSE_CHECKOUT_PATH" && ' +
854+ '$SD_GIT_WRAPPER "git checkout"; fi'
855+ ) ;
856+
836857 // Reset to SHA
837858 if ( config . prRef ) {
838859 command . push ( `$SD_GIT_WRAPPER "git reset --hard '${ doubleQuoteEscapedBranch } ' --"` ) ;
0 commit comments