2021-09-27 10:38:12 +02:00
|
|
|
|
<#
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.SYNOPSIS
|
2021-10-04 21:29:23 +02:00
|
|
|
|
Clones well-known Git repositories into a folder
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.DESCRIPTION
|
2021-10-04 21:29:23 +02:00
|
|
|
|
clone-repos.ps1 [<folder>]
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.EXAMPLE
|
2021-10-04 21:29:23 +02:00
|
|
|
|
PS> ./clone-repos C:\Users\Markus\Repos
|
2021-08-29 17:50:03 +02:00
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz · License: CC0
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2020-12-29 15:14:21 +01:00
|
|
|
|
#>
|
2020-12-01 12:24:56 +01:00
|
|
|
|
|
2021-10-04 21:29:23 +02:00
|
|
|
|
param([string]$folder = "$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()
|
|
|
|
|
|
2021-10-04 21:29:23 +02:00
|
|
|
|
if (-not(test-path "$folder" -pathType container)) { throw "Can't access directory: $folder" }
|
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-06-30 18:36:58 +02:00
|
|
|
|
$Table = import-csv "$PSScriptRoot/../Data/git-repos.csv"
|
2021-07-02 15:56:38 +02:00
|
|
|
|
$TableCount = $Table.count
|
|
|
|
|
"Found $TableCount entries in Data/git-repos.csv database..."
|
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-06-30 18:36:58 +02:00
|
|
|
|
[string]$FolderName = $Row.FolderName
|
|
|
|
|
[string]$Branch = $Row.Branch
|
|
|
|
|
[string]$Shallow = $Row.Shallow
|
|
|
|
|
[string]$URL = $Row.URL
|
2021-06-28 20:58:37 +02:00
|
|
|
|
|
2021-10-04 21:29:23 +02:00
|
|
|
|
if (test-path "$folder/$FolderName" -pathType container) {
|
2021-06-28 21:29:12 +02:00
|
|
|
|
"📂$FolderName exists, skipping..."
|
2021-01-21 15:19:24 +01:00
|
|
|
|
continue
|
|
|
|
|
}
|
2021-06-30 18:36:58 +02:00
|
|
|
|
if ($Shallow -eq "yes") {
|
2021-07-02 15:48:00 +02:00
|
|
|
|
"🢃 Cloning to 📂$FolderName, $Branch branch, shallow..."
|
2021-10-04 21:29:23 +02:00
|
|
|
|
& git clone --branch "$Branch" --depth 1 --shallow-submodules --recurse-submodules "$URL" "$folder/$FolderName"
|
2021-06-30 18:36:58 +02:00
|
|
|
|
} else {
|
2021-07-02 15:48:00 +02:00
|
|
|
|
"🢃 Cloning to 📂$FolderName, $Branch branch, full history..."
|
2021-10-04 21:29:23 +02:00
|
|
|
|
& git clone --branch "$Branch" --recurse-submodules "$URL" "$folder/$FolderName"
|
2021-06-30 18:36:58 +02:00
|
|
|
|
}
|
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-10-04 21:29:23 +02:00
|
|
|
|
"✔️ cloned $Count Git repositories into 📂$folder in $Elapsed sec"
|
2021-09-27 10:09:45 +02:00
|
|
|
|
exit 0 # success
|
2020-12-09 10:30:55 +01:00
|
|
|
|
} catch {
|
2021-09-16 20:19:10 +02:00
|
|
|
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
2020-12-09 10:30:55 +01:00
|
|
|
|
exit 1
|
|
|
|
|
}
|