Some fixes to PowerLine prompt + New command
Start-GitHubDirDownload - Download a specific directory using github's SVN support. Requires subversion package be installed.
This commit is contained in:
parent
86c1189211
commit
6ff3357c58
2 changed files with 67 additions and 3 deletions
61
base/Start-GitHubDirDownload.ps1
Normal file
61
base/Start-GitHubDirDownload.ps1
Normal file
|
@ -0,0 +1,61 @@
|
|||
[CmdletBinding()]param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]$GitHubProject,
|
||||
[string]$Directory,
|
||||
[string]$Destination='.',
|
||||
[switch]$Update,
|
||||
[string]$BackupRelativePath="<auto>"
|
||||
)
|
||||
|
||||
$local:testReq = $(try {
|
||||
Invoke-WebRequest "https://github.com/$GitHubProject/tree/HEAD/$Directory" -UseBasicParsing -ErrorAction Stop
|
||||
} catch {})
|
||||
if( 200 -ne $testReq.StatusCode ) {
|
||||
Write-Verbose $($testReq|Format-List|Out-String)
|
||||
Write-Error "Request failed for $GitHubProject : $Directory"
|
||||
return
|
||||
}
|
||||
|
||||
$DestFull = Get-Item $(Join-Path $Destination '.')
|
||||
Write-Verbose "DestFull: $($DestFull | Format-List | Out-String)"
|
||||
|
||||
$local:tmpFile = ""
|
||||
New-TemporaryFile | Select-Object -ExpandProperty FullName -OutVariable tmpFile | Remove-Item -Force
|
||||
$tmpPath = New-Item -ItemType Directory $tmpFile
|
||||
Remove-Variable tmpFile
|
||||
Push-Location $tmpPath
|
||||
Write-Verbose "tmp $($tmpPath.FullName) created"
|
||||
|
||||
if( $BackupRelativePath -eq "<auto>" ) {
|
||||
$BackupRelativePath = ".overitten.on.#Timestamp#"
|
||||
}
|
||||
$BackupRelativePath = $BackupRelativePath -replace "#Timestamp#",$(Get-Date -Format "yyyyMMdd-HHmmss")
|
||||
|
||||
Write-Verbose "Fetching $Directory..."
|
||||
$null = & svn checkout "https://github.com/$GitHubProject/trunk/$Directory"
|
||||
$local:dirName = Split-Path -Leaf $Directory
|
||||
|
||||
Remove-Item -Recurse (Join-Path $dirName '.svn') -Force
|
||||
|
||||
Get-ChildItem -File -Force $dirName -Recurse | ForEach-Object {
|
||||
$local:item = $_.FullName.Replace($tmpPath.FullName,'') -replace '^/',''
|
||||
$local:dst = Join-Path $DestFull.FullName $item
|
||||
if( Test-Path $dst ) {
|
||||
if( -not $Update ) {
|
||||
Write-Verbose "$dst already exists, skipping..."
|
||||
return
|
||||
}
|
||||
if( -not (Compare-Object (Get-Content $item) (Get-Content $dst) -CaseSensitive) ) {
|
||||
Write-Verbose "$dst already updated, skipping..."
|
||||
return
|
||||
}
|
||||
$local:bkPath = Join-Path $DestFull.FullName (Split-Path -Parent $item) $BackupRelativePath (Split-Path -leaf $item)
|
||||
$null = New-Item -ItemType Directory -Force (Split-Path -Parent $bkPath) -ErrorAction Stop
|
||||
Move-Item -Force $dst $bkPath
|
||||
}
|
||||
Write-Verbose "Copy-Item -Force $_ $dst -PassThru"
|
||||
Copy-Item -Force $_ $dst -PassThru
|
||||
}
|
||||
|
||||
Pop-Location
|
||||
Remove-Item -Recurse $tmpPath -Force
|
Loading…
Add table
Add a link
Reference in a new issue