parameters:
# name of the repo to checkout
# for most cases, leave as default 'self'
- name: checkoutRepo
  type: string
  default: 'self'
- name: sparseCheckoutDir
  type: string
  default: ''
# submodule download behaviour
# change to 'recursive' for repos with submodules
- name: submoduleBehaviour
  type: string
  default: 'true'

steps:
  - checkout: ${{ parameters.checkoutRepo }}
    clean: true
    submodules: ${{ parameters.submoduleBehaviour }}
    retryCountOnTaskFailure: 3
    fetchFilter: blob:none
    ${{ if ne(parameters.sparseCheckoutDir, '') }}:
      sparseCheckoutDirectories: ${{ parameters.sparseCheckoutDir }}
      path: sparse
  - ${{ if ne(parameters.sparseCheckoutDir, '') }}:
    - task: Bash@3
      displayName: Symlink sparse checkout
      inputs:
        targetType: inline
        script: ln -s $(Agent.BuildDirectory)/sparse/${{ parameters.sparseCheckoutDir }} $(Agent.BuildDirectory)/s
