Skip to content

Commit 83b1c29

Browse files
azure-sdkbenbp
authored andcommitted
Revert "Add full clone fallback to sparse checkout (Azure#3661)" (Azure#3851)
This reverts commit 7605ead00308dd20f20f2afe5acc4ec9900a2c47. Co-authored-by: Ben Broderick Phillips <[email protected]>
1 parent b46e169 commit 83b1c29

File tree

1 file changed

+37
-87
lines changed

1 file changed

+37
-87
lines changed

eng/common/pipelines/templates/steps/sparse-checkout.yml

Lines changed: 37 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -23,79 +23,52 @@ steps:
2323
# Define this inline, because of the chicken/egg problem with loading a script when nothing
2424
# has been checked out yet.
2525
script: |
26-
function Clone([Hashtable]$repository)
27-
{
28-
if (Test-Path .git) {
29-
Write-Warning "Deleting existing git repository"
30-
Write-Host "Remove-Item -Force -Recurse ./*"
31-
Remove-Item -Force -Recurse ./*
32-
}
33-
34-
Write-Host "git clone https://github.com/$($repository.Name) ."
35-
git clone https://github.com/$($repository.Name) .
36-
if ($LASTEXITCODE) {
37-
exit $LASTEXITCODE
38-
}
39-
Write-Host "git -c advice.detachedHead=false checkout $($repository.Commitish)"
40-
# This will use the default branch if repo.Commitish is empty
41-
git -c advice.detachedHead=false checkout $($repository.Commitish)
42-
if ($LASTEXITCODE) {
43-
exit $LASTEXITCODE
44-
}
45-
}
46-
4726
function SparseCheckout([Array]$paths, [Hashtable]$repository)
4827
{
49-
if (Test-Path .git/info/sparse-checkout) {
50-
$hasInitialized = $true
51-
Write-Host "Repository $($repository.Name) has already been initialized. Skipping this step."
52-
} else {
53-
Write-Host "Repository $($repository.Name) is being initialized."
54-
55-
Write-Host "git clone --no-checkout --filter=tree:0 https://github.com/$($repository.Name) ."
56-
git clone --no-checkout --filter=tree:0 https://github.com/$($repository.Name) .
57-
if ($LASTEXITCODE) {
58-
throw
28+
$dir = $repository.WorkingDirectory
29+
if (!$dir) {
30+
$dir = "./$($repository.Name)"
5931
}
32+
New-Item $dir -ItemType Directory -Force
33+
Push-Location $dir
6034
61-
Write-Host "git sparse-checkout init"
62-
git sparse-checkout init
63-
if ($LASTEXITCODE) {
64-
throw
65-
}
35+
if (Test-Path .git/info/sparse-checkout) {
36+
$hasInitialized = $true
37+
Write-Host "Repository $($repository.Name) has already been initialized. Skipping this step."
38+
} else {
39+
Write-Host "Repository $($repository.Name) is being initialized."
40+
41+
Write-Host "git clone --no-checkout --filter=tree:0 https://github.com/$($repository.Name) ."
42+
git clone --no-checkout --filter=tree:0 https://github.com/$($repository.Name) .
6643
67-
# Set non-cone mode otherwise path filters will not work in git >= 2.37.0
68-
# See https://github.blog/2022-06-27-highlights-from-git-2-37/#tidbits
69-
Write-Host "git sparse-checkout set --no-cone '/*' '!/*/' '/eng'"
70-
git sparse-checkout set --no-cone '/*' '!/*/' '/eng'
71-
if ($LASTEXITCODE) {
72-
throw
44+
Write-Host "git sparse-checkout init"
45+
git sparse-checkout init
46+
47+
# Set non-cone mode otherwise path filters will not work in git >= 2.37.0
48+
# See https://github.blog/2022-06-27-highlights-from-git-2-37/#tidbits
49+
Write-Host "git sparse-checkout set --no-cone '/*' '!/*/' '/eng'"
50+
git sparse-checkout set --no-cone '/*' '!/*/' '/eng'
7351
}
74-
}
7552
76-
# Prevent wildcard expansion in Invoke-Expression (e.g. for checkout path '/*')
77-
$quotedPaths = $paths | ForEach-Object { "'$_'" }
78-
$gitsparsecmd = "git sparse-checkout add $quotedPaths"
79-
Write-Host $gitsparsecmd
80-
Invoke-Expression -Command $gitsparsecmd
81-
if ($LASTEXITCODE) {
82-
throw
83-
}
53+
# Prevent wildcard expansion in Invoke-Expression (e.g. for checkout path '/*')
54+
$quotedPaths = $paths | ForEach-Object { "'$_'" }
55+
$gitsparsecmd = "git sparse-checkout add $quotedPaths"
56+
Write-Host $gitsparsecmd
57+
Invoke-Expression -Command $gitsparsecmd
8458
85-
Write-Host "Set sparse checkout paths to:"
86-
Get-Content .git/info/sparse-checkout
59+
Write-Host "Set sparse checkout paths to:"
60+
Get-Content .git/info/sparse-checkout
8761
88-
# sparse-checkout commands after initial checkout will auto-checkout again
89-
if (!$hasInitialized) {
90-
Write-Host "git -c advice.detachedHead=false checkout $($repository.Commitish)"
91-
# This will use the default branch if repo.Commitish is empty
92-
git -c advice.detachedHead=false checkout $($repository.Commitish)
93-
if ($LASTEXITCODE) {
94-
throw
62+
# sparse-checkout commands after initial checkout will auto-checkout again
63+
if (!$hasInitialized) {
64+
Write-Host "git -c advice.detachedHead=false checkout $($repository.Commitish)"
65+
# This will use the default branch if repo.Commitish is empty
66+
git -c advice.detachedHead=false checkout $($repository.Commitish)
67+
} else {
68+
Write-Host "Skipping checkout as repo has already been initialized"
9569
}
96-
} else {
97-
Write-Host "Skipping checkout as repo has already been initialized"
98-
}
70+
71+
Pop-Location
9972
}
10073
10174
# Paths may be sourced as a yaml object literal OR a dynamically generated variable json string.
@@ -104,30 +77,7 @@ steps:
10477
# Replace windows backslash paths, as Azure Pipelines default directories are sometimes formatted like 'D:\a\1\s'
10578
$repositories = '${{ convertToJson(parameters.Repositories) }}' -replace '\\', '/' | ConvertFrom-Json -AsHashtable
10679
foreach ($repo in $Repositories) {
107-
$dir = $repo.WorkingDirectory
108-
if (!$dir) {
109-
$dir = "./$($repo.Name)"
110-
}
111-
New-Item $dir -ItemType Directory -Force
112-
Push-Location $dir
113-
114-
try {
115-
# Enable global override if there are sparse checkout issues
116-
if ('$(SkipSparseCheckout)' -ne 'true') {
117-
try {
118-
SparseCheckout $paths $repo
119-
} catch {
120-
# Fallback to full clone if sparse checkout is not working properly
121-
Write-Warning "Sparse checkout failed, falling back to full clone"
122-
Clone $repo
123-
}
124-
} else {
125-
Write-Warning "Sparse checkout disabled, performing full clone"
126-
Clone $repo
127-
}
128-
} finally {
129-
Pop-Location
130-
}
80+
SparseCheckout $paths $repo
13181
}
13282
pwsh: true
13383
workingDirectory: $(System.DefaultWorkingDirectory)

0 commit comments

Comments
 (0)