mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-28 20:58:46 +02:00
Update clone-repos.ps1 and list-cli-tools.ps1
This commit is contained in:
parent
92e029f433
commit
141a867b06
@ -2,9 +2,9 @@
|
|||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Clones Git repositories
|
Clones Git repositories
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script clones well-known Git repositories into a folder.
|
This PowerShell script clones well-known Git repositories into a target directory.
|
||||||
.PARAMETER folder
|
.PARAMETER targetDir
|
||||||
Specifies the target folder (default is current working directory)
|
Specifies the target directory (current working directory by default)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./clone-repos C:\Repos
|
PS> ./clone-repos C:\Repos
|
||||||
.LINK
|
.LINK
|
||||||
@ -13,7 +13,7 @@
|
|||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$FolderPath = "$PWD")
|
param([string]$TargetDir = "$PWD")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
@ -22,14 +22,14 @@ try {
|
|||||||
& git --version
|
& git --version
|
||||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||||
|
|
||||||
Write-Host "⏳ (2) Loading data from Data/git-repos.csv... " -noNewline
|
Write-Host "⏳ (2) Loading Data/known-git-repos.csv... " -noNewline
|
||||||
$Table = Import-CSV "$PSScriptRoot/../Data/git-repos.csv"
|
$Table = Import-CSV "$PSScriptRoot/../Data/known-git-repos.csv"
|
||||||
$NumEntries = $Table.count
|
$NumEntries = $Table.count
|
||||||
Write-Host "$NumEntries Git repositories"
|
Write-Host "$NumEntries Git repositories"
|
||||||
|
|
||||||
$ParentFolderName = (Get-Item "$FolderPath").Name
|
$TargetDirName = (Get-Item "$TargetDir").Name
|
||||||
Write-Host "⏳ (3) Checking target folder... 📂$ParentFolderName"
|
Write-Host "⏳ (3) Checking target folder... 📂$TargetDirName"
|
||||||
if (-not(Test-Path "$FolderPath" -pathType container)) { throw "Can't access directory: $FolderPath" }
|
if (-not(Test-Path "$TargetDir" -pathType container)) { throw "Can't access directory: $TargetDir" }
|
||||||
|
|
||||||
|
|
||||||
[int]$Step = 3
|
[int]$Step = 3
|
||||||
@ -43,27 +43,27 @@ try {
|
|||||||
[string]$URL = $Row.URL
|
[string]$URL = $Row.URL
|
||||||
$Step++
|
$Step++
|
||||||
|
|
||||||
if (Test-Path "$FolderPath/$FolderName" -pathType container) {
|
if (Test-Path "$TargetDir/$FolderName" -pathType container) {
|
||||||
"⏳ ($Step/$($NumEntries + 4)) Skipping 📂$FolderName - exists already..."
|
"⏳ ($Step/$($NumEntries + 4)) Skipping 📂$FolderName - exists already..."
|
||||||
$Skipped++
|
$Skipped++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ($Full -eq "yes") {
|
if ($Full -eq "yes") {
|
||||||
"⏳ ($Step/$($NumEntries + 4)) Cloning into 📂$($FolderName) ($Branch branch with full history)..."
|
"⏳ ($Step/$($NumEntries + 4)) Cloning into 📂$($FolderName) ($Branch branch with full history)..."
|
||||||
& git clone --branch "$Branch" --recurse-submodules "$URL" "$FolderPath/$FolderName"
|
& git clone --branch "$Branch" --recurse-submodules "$URL" "$TargetDir/$FolderName"
|
||||||
if ($lastExitCode -ne "0") { throw "'git clone --branch $Branch $URL' failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne "0") { throw "'git clone --branch $Branch $URL' failed with exit code $lastExitCode" }
|
||||||
} else {
|
} else {
|
||||||
"⏳ ($Step/$($NumEntries + 4)) Cloning $Branch branch into 📂$FolderName..."
|
"⏳ ($Step/$($NumEntries + 4)) Cloning $Branch branch into 📂$FolderName..."
|
||||||
& git clone --branch "$Branch" --single-branch --recurse-submodules "$URL" "$FolderPath/$FolderName"
|
& git clone --branch "$Branch" --single-branch --recurse-submodules "$URL" "$TargetDir/$FolderName"
|
||||||
if ($lastExitCode -ne "0") { throw "'git clone --branch $Branch $URL' failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne "0") { throw "'git clone --branch $Branch $URL' failed with exit code $lastExitCode" }
|
||||||
}
|
}
|
||||||
$Cloned++
|
$Cloned++
|
||||||
}
|
}
|
||||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||||
if ($Cloned -eq 1) {
|
if ($Cloned -eq 1) {
|
||||||
"✔️ 1 repository cloned into 📂$ParentFolderName in $Elapsed sec ($Skipped skipped)."
|
"✔️ 1 repository cloned into 📂$TargetDirName in $Elapsed sec ($Skipped skipped)."
|
||||||
} else {
|
} else {
|
||||||
"✔️ $Cloned repositories cloned into 📂$ParentFolderName in $Elapsed sec ($Skipped skipped)."
|
"✔️ $Cloned repositories cloned into 📂$TargetDirName in $Elapsed sec ($Skipped skipped)."
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -119,6 +119,7 @@ function ListCmdTools {
|
|||||||
Test dircolors "--version"
|
Test dircolors "--version"
|
||||||
Test dirname "--version"
|
Test dirname "--version"
|
||||||
Test dism ""
|
Test dism ""
|
||||||
|
Test dmidecode "--version"
|
||||||
Test dos2unix "--version"
|
Test dos2unix "--version"
|
||||||
Test driverquery ""
|
Test driverquery ""
|
||||||
Test du "--version"
|
Test du "--version"
|
||||||
|
Loading…
Reference in New Issue
Block a user