0

My use case is I want to create a shallow clone using shallow-since as noted in How do I remove the old history from a git repository?

However, checkout does not provide that option.

My assumption would be to do a

- checkout: none
- bash: |
    git clone $(Build.Repository.Uri) \
      --shallow-since 2020-01-01 \
      $(Build.SourcesDirectory)

But I am not sure where to put the credentials. The variables I can probably look up.

I've added a feature request for checkout so I won't need a workaround in the future.

I am suspecting it is something with System.AccessToken

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265
  • Thanks to the answer I got it to the point where it shows At present Git used in Azure Devops does not support `shallow-since` as noted by this error message ``` fatal: Server does not support --shallow-since ``` – Archimedes Trajano May 20 '21 at 13:36

2 Answers2

3

Rather than using URL manipulation, I use header modification. This avoids using sed

steps:
  - checkout: none
  - bash: |
      git clone $(Build.Repository.Uri) \
        -c http.extraheader="Authorization: Bearer $(System.AccessToken)" \
        --single-branch \
        --no-tags \
         $(Build.SourcesDirectory)
      # --shallow-since 2020-01-01

Unfortunately, Azure DevOps does not support --shallow-since as of this writing.

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265
2

You have 2 options:

  • Inject your PAT in the clone url:

    https://{PAT}@dev.azure.com/{organization}/{project}/_git/{repo-name}
    
  • Inject the System Access Token in the clone url:

    https://$(System.AccessToken)@dev.azure.com/{organization}/{project}/_git/{repo-name}
    
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114