Skip to content

Commit

Permalink
WIP: handle git errors while cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
xxthunder committed Jun 11, 2023
1 parent 9b0e949 commit a4bfe5d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
- name: Test Scoop Install command
shell: pwsh
run: |
git config --global protocol.https.allow never
./install.ps1 -RunAsAdmin
echo "~\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Test scoop command availability
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true
}
},
"iis.configDir": "",
"pester.autoRunOnSave": false
}
21 changes: 16 additions & 5 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function Test-Prerequisite {
}

# Ensure Robocopy.exe is accessible
if (!([bool](Get-Command -Name 'robocopy' -ErrorAction SilentlyContinue))) {
if (!(Test-CommandAvailable('robocopy'))) {
Deny-Install "Scoop requires 'C:\Windows\System32\Robocopy.exe' to work. Please make sure 'C:\Windows\System32' is in your PATH."
}

Expand All @@ -149,7 +149,7 @@ function Test-Prerequisite {
}

# Test if scoop is installed, by checking if scoop command exists.
if ([bool](Get-Command -Name 'scoop' -ErrorAction SilentlyContinue)) {
if (Test-CommandAvailable('scoop')) {
Deny-Install "Scoop is already installed. Run 'scoop update' to get the latest version."
}
}
Expand Down Expand Up @@ -548,7 +548,7 @@ function Test-CommandAvailable {
[Parameter(Mandatory = $True, Position = 0)]
[String] $Command
)
return [Boolean](Get-Command $Command -ErrorAction Ignore)
return [Boolean](Get-Command $Command -ErrorAction SilentlyContinue)
}

function Install-Scoop {
Expand All @@ -563,6 +563,7 @@ function Install-Scoop {
# Download scoop from GitHub
Write-InstallInfo "Downloading ..."
$downloader = Get-Downloader
[bool]$downloadZipsRequired = $True

if (Test-CommandAvailable('git')) {
$old_https = $env:HTTPS_PROXY
Expand All @@ -575,15 +576,25 @@ function Install-Scoop {
}
Write-Verbose "Cloning $SCOOP_PACKAGE_GIT_REPO to $SCOOP_APP_DIR"
git clone -q $SCOOP_PACKAGE_GIT_REPO $SCOOP_APP_DIR
if (-Not $?) {
Write-Error "Cloning failed. Falling back to downloading zip files."
}
Write-Verbose "Cloning $SCOOP_MAIN_BUCKET_GIT_REPO to $SCOOP_MAIN_BUCKET_DIR"
git clone -q $SCOOP_MAIN_BUCKET_GIT_REPO $SCOOP_MAIN_BUCKET_DIR
if (-Not $?) {
Write-Error "Cloning failed. Falling back to downloading zip files."
}
$downloadZipsRequired = $False
} catch {
Get-Error $_
Write-Output "$($_.Exception.Message)"
$Global:LastExitCode = 0
} finally {
$env:HTTPS_PROXY = $old_https
$env:HTTP_PROXY = $old_http
}
} else {
}

if ($downloadZipsRequired) {
# 1. download scoop
$scoopZipfile = "$SCOOP_APP_DIR\scoop.zip"
if (!(Test-Path $SCOOP_APP_DIR)) {
Expand Down
13 changes: 13 additions & 0 deletions test/install.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,16 @@ Describe 'Get-Downloader' -Tag 'Proxy' {
}
}
}

Describe 'Test-CommandAvailable' -Tag 'CommandLine' {
Context 'Command available' {
It 'Returns $true' {
Test-CommandAvailable -Command 'git' | Should -Be $true
}
}
Context 'Command not available' {
It 'Returns $false' {
Test-CommandAvailable -Command 'notavailable' | Should -Be $false
}
}
}

0 comments on commit a4bfe5d

Please sign in to comment.