2021-04-21 19:53:52 +02:00
|
|
|
|
<#
|
2021-04-21 11:28:12 +02:00
|
|
|
|
.SYNTAX clone-repos.ps1 [<parent-dir>]
|
|
|
|
|
.DESCRIPTION clones well-known Git repositories under the current/given directory.
|
2021-03-22 20:10:18 +01:00
|
|
|
|
.LINK https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES Author: Markus Fleschutz / License: CC0
|
2020-12-29 15:14:21 +01:00
|
|
|
|
#>
|
2020-12-01 12:24:56 +01:00
|
|
|
|
|
2021-04-21 11:28:12 +02:00
|
|
|
|
param($ParentDir = "$PWD")
|
2021-02-28 18:49:53 +01:00
|
|
|
|
|
2021-02-13 10:26:14 +01:00
|
|
|
|
try {
|
2021-04-21 11:28:12 +02:00
|
|
|
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
|
|
|
|
|
|
|
|
|
if (-not(test-path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" }
|
2021-04-19 19:39:52 +02:00
|
|
|
|
|
2021-04-17 11:29:32 +02:00
|
|
|
|
$Null = (git --version)
|
|
|
|
|
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
2020-12-01 12:24:56 +01:00
|
|
|
|
|
2021-04-19 19:39:52 +02:00
|
|
|
|
$Table = import-csv "$PSScriptRoot/../Data/git-repositories.csv"
|
2021-01-20 16:11:38 +01:00
|
|
|
|
|
2021-04-21 11:28:12 +02:00
|
|
|
|
[int]$Count = 0
|
2021-01-20 16:11:38 +01:00
|
|
|
|
foreach($Row in $Table) {
|
2021-05-26 19:47:00 +02:00
|
|
|
|
$Directory = $Row.Directory
|
|
|
|
|
$Branch = $Row.Branch
|
2021-01-20 16:11:38 +01:00
|
|
|
|
$URL = $Row.URL
|
2021-05-26 19:47:00 +02:00
|
|
|
|
if (test-path "$ParentDir/$Directory" -pathType container) {
|
|
|
|
|
"📂$Directory exists already, skipping..."
|
2021-01-21 15:19:24 +01:00
|
|
|
|
continue
|
|
|
|
|
}
|
2021-05-26 19:47:00 +02:00
|
|
|
|
"🢃 Cloning 📂$Directory from $URL, $Branch branch..."
|
|
|
|
|
& git clone --branch "$Branch" --recurse-submodules "$URL" "$ParentDir/$Directory"
|
2021-02-15 12:00:23 +01:00
|
|
|
|
if ($lastExitCode -ne "0") { throw "'git clone $URL' failed" }
|
2021-04-21 11:28:12 +02:00
|
|
|
|
$Count++
|
2020-12-01 12:24:56 +01:00
|
|
|
|
}
|
2021-04-21 16:43:08 +02:00
|
|
|
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
2021-06-07 20:06:55 +02:00
|
|
|
|
"✔️ cloned $Count Git repositories at 📂$ParentDir in $Elapsed sec"
|
2020-12-09 10:30:55 +01:00
|
|
|
|
exit 0
|
|
|
|
|
} catch {
|
2021-05-02 21:30:48 +02:00
|
|
|
|
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2020-12-09 10:30:55 +01:00
|
|
|
|
exit 1
|
|
|
|
|
}
|