mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-21 10:47:01 +01:00
Update clone-repos.ps1
This commit is contained in:
parent
2f561eeef9
commit
0bb7dba477
@ -6,50 +6,55 @@
|
||||
.PARAMETER folder
|
||||
Specifies the target folder
|
||||
.EXAMPLE
|
||||
PS> ./clone-repos C:\Users\Markus\Repos
|
||||
PS> ./clone-repos C:\Repos
|
||||
.NOTES
|
||||
Author: Markus Fleschutz · License: CC0
|
||||
Author: Markus Fleschutz / License: CC0
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
#>
|
||||
|
||||
param([string]$folder = "$PWD")
|
||||
param([string]$FolderPath = "$PWD")
|
||||
|
||||
try {
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
if (-not(test-path "$folder" -pathType container)) { throw "Can't access directory: $folder" }
|
||||
if (-not(test-path "$FolderPath" -pathType container)) { throw "Can't access directory: $FolderPath" }
|
||||
$ParentFolderName = (get-item "$FolderPath").Name
|
||||
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
$Table = import-csv "$PSScriptRoot/../Data/git-repos.csv"
|
||||
$TableCount = $Table.count
|
||||
"Found $TableCount entries in Data/git-repos.csv database..."
|
||||
$NumEntries = $Table.count
|
||||
"Found $NumEntries entries in database Data/git-repos.csv..."
|
||||
|
||||
[int]$Count = 0
|
||||
[int]$Step = 0
|
||||
[int]$Cloned = 0
|
||||
[int]$Skipped = 0
|
||||
foreach($Row in $Table) {
|
||||
[string]$FolderName = $Row.FolderName
|
||||
[string]$Branch = $Row.Branch
|
||||
[string]$Shallow = $Row.Shallow
|
||||
[string]$URL = $Row.URL
|
||||
$Step++
|
||||
|
||||
if (test-path "$folder/$FolderName" -pathType container) {
|
||||
"📂$FolderName exists, skipping..."
|
||||
if (test-path "$FolderPath/$FolderName" -pathType container) {
|
||||
"⏳ Step $Step/$($NumEntries): skipping already existing 📂$($FolderName)..."
|
||||
$Skipped++
|
||||
continue
|
||||
}
|
||||
if ($Shallow -eq "yes") {
|
||||
"🢃 Cloning to 📂$FolderName, $Branch branch, shallow..."
|
||||
& git clone --branch "$Branch" --depth 1 --shallow-submodules --recurse-submodules "$URL" "$folder/$FolderName"
|
||||
"⏳ Step $Step/$($NumEntries): cloning shallow $Branch branch to 📂$($FolderName)..."
|
||||
& git clone --branch "$Branch" --depth 1 --shallow-submodules --recurse-submodules "$URL" "$FolderPath/$FolderName"
|
||||
} else {
|
||||
"🢃 Cloning to 📂$FolderName, $Branch branch, full history..."
|
||||
& git clone --branch "$Branch" --recurse-submodules "$URL" "$folder/$FolderName"
|
||||
"⏳ Step $Step/$($NumEntries): cloning full $Branch branch to 📂$FolderName..."
|
||||
& git clone --branch "$Branch" --recurse-submodules "$URL" "$FolderPath/$FolderName"
|
||||
}
|
||||
if ($lastExitCode -ne "0") { throw "'git clone $URL' failed" }
|
||||
$Count++
|
||||
$Cloned++
|
||||
}
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ cloned $Count Git repositories into 📂$folder in $Elapsed sec"
|
||||
"✔️ $Cloned Git repositories cloned, $Skipped skipped in 📂$ParentFolderName in $Elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
||||
|
Loading…
Reference in New Issue
Block a user