Update build-repos.ps1, clone-repos.ps1, fetch-repos.ps1, and

pull-repos.ps1
This commit is contained in:
Markus Fleschutz 2022-08-18 09:46:16 +02:00
parent ddb6484a9d
commit 0cdf5ec9a1
4 changed files with 28 additions and 27 deletions

View File

@ -1,16 +1,16 @@
<# <#
.SYNOPSIS .SYNOPSIS
Builds all Git repositories in a folder Builds Git repositories
.DESCRIPTION .DESCRIPTION
This PowerShell script builds all Git repositories in a given folder. This PowerShell script builds all Git repositories in a folder.
.PARAMETER ParentDir .PARAMETER ParentDir
Specifies the path to the folder containing the Git repositories Specifies the path to the parent folder
.EXAMPLE .EXAMPLE
PS> ./build-repos C:\MyRepos PS> ./build-repos C:\MyRepos
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
Author: Markus Fleschutz / License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
param([string]$ParentDir = "$PWD") param([string]$ParentDir = "$PWD")
@ -18,12 +18,12 @@ param([string]$ParentDir = "$PWD")
try { try {
$StopWatch = [system.diagnostics.stopwatch]::startNew() $StopWatch = [system.diagnostics.stopwatch]::startNew()
if (-not(test-path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" } $ParentDirName = (Get-Item "$ParentDir").Name
"⏳ Step 1 - Checking parent folder 📂$ParentDirName..."
$Folders = (get-childItem "$ParentDir" -attributes Directory) if (-not(Test-Path "$ParentDir" -pathType container)) { throw "Can't access folder: $ParentDir" }
$Folders = (Get-ChildItem "$ParentDir" -attributes Directory)
$FolderCount = $Folders.Count $FolderCount = $Folders.Count
$ParentDirName = (get-item "$ParentDir").Name "Found $FolderCount subfolders."
"Found $FolderCount subfolders in 📂$ParentDirName..."
[int]$Step = 1 [int]$Step = 1
foreach ($Folder in $Folders) { foreach ($Folder in $Folders) {
@ -37,4 +37,4 @@ try {
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -22,15 +22,16 @@ 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" }
"⏳ Step 2 - Checking folder..." "⏳ Step 2 - Checking target folder..."
if (-not(Test-Path "$FolderPath" -pathType container)) { throw "Can't access directory: $FolderPath" } if (-not(Test-Path "$FolderPath" -pathType container)) { throw "Can't access directory: $FolderPath" }
$ParentFolderName = (Get-Item "$FolderPath").Name $ParentFolderName = (Get-Item "$FolderPath").Name
"⏳ Step 3 - Checking table in Data/git-repos.csv..."
$Table = Import-CSV "$PSScriptRoot/../Data/git-repos.csv" $Table = Import-CSV "$PSScriptRoot/../Data/git-repos.csv"
$NumEntries = $Table.count $NumEntries = $Table.count
"⏳ Step 3 - Found $NumEntries entries in Data/git-repos.csv." "Found $NumEntries entries."
[int]$Step = 3 [int]$Step = 4
[int]$Cloned = 0 [int]$Cloned = 0
[int]$Skipped = 0 [int]$Skipped = 0
foreach($Row in $Table) { foreach($Row in $Table) {
@ -41,16 +42,16 @@ try {
$Step++ $Step++
if (test-path "$FolderPath/$FolderName" -pathType container) { if (test-path "$FolderPath/$FolderName" -pathType container) {
"⏳ Step $Step/$($NumEntries + 3) - Skipping 📂$($FolderName) (exists already)..." "⏳ Step $Step/$($NumEntries + 4) - Skipping 📂$($FolderName) (exists already)..."
$Skipped++ $Skipped++
continue continue
} }
if ($Full -eq "yes") { if ($Full -eq "yes") {
"⏳ Step $Step/$($NumEntries + 3) - Cloning into 📂$($FolderName) ($Branch branch with full history)..." "⏳ Step $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" "$FolderPath/$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 $Step/$($NumEntries + 3) - Cloning into 📂$FolderName ($Branch branch only)..." "⏳ Step $Step/$($NumEntries + 4) - Cloning into 📂$FolderName ($Branch branch only)..."
& git clone --branch "$Branch" --single-branch --recurse-submodules "$URL" "$FolderPath/$FolderName" & git clone --branch "$Branch" --single-branch --recurse-submodules "$URL" "$FolderPath/$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" }
} }

View File

@ -1,6 +1,6 @@
<# <#
.SYNOPSIS .SYNOPSIS
Fetches updates for all Git repositories in a folder Fetches updates for Git repositories
.DESCRIPTION .DESCRIPTION
This PowerShell script fetches updates for all Git repositories in a folder (including submodules). This PowerShell script fetches updates for all Git repositories in a folder (including submodules).
.PARAMETER ParentDir .PARAMETER ParentDir
@ -22,11 +22,12 @@ 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" }
if (-not(Test-Path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" } $ParentDirName = (Get-Item "$ParentDir").Name
"⏳ Step 2 - Checking parent folder 📂$ParentDirName..."
if (-not(Test-Path "$ParentDir" -pathType container)) { throw "Can't access folder: $ParentDir" }
$Folders = (Get-ChildItem "$ParentDir" -attributes Directory) $Folders = (Get-ChildItem "$ParentDir" -attributes Directory)
$NumFolders = $Folders.Count $NumFolders = $Folders.Count
$ParentDirName = (Get-Item "$ParentDir").Name "Found $NumFolders subfolders."
"⏳ Step 2 - Found $NumFolders subfolders in 📂$ParentDirName..."
[int]$Step = 3 [int]$Step = 3
foreach ($Folder in $Folders) { foreach ($Folder in $Folders) {

View File

@ -22,19 +22,18 @@ 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" }
"⏳ Step 2 - Checking folder..." $ParentDirName = (Get-Item "$ParentDir").Name
if (-not(Test-Path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" } "⏳ Step 2 - Checking parent folder 📂$ParentDirName..."
if (-not(Test-Path "$ParentDir" -pathType container)) { throw "Can't access folder: $ParentDir" }
$Folders = (Get-ChildItem "$ParentDir" -attributes Directory) $Folders = (Get-ChildItem "$ParentDir" -attributes Directory)
$NumFolders = $Folders.Count $NumFolders = $Folders.Count
$ParentDirName = (Get-Item "$ParentDir").Name "Found $NumFolders subfolders."
"⏳ Step 3 - Found $NumFolders subfolders in 📂$ParentDirName... "
[int]$Step = 4 [int]$Step = 3
[int]$Failed = 0 [int]$Failed = 0
foreach ($Folder in $Folders) { foreach ($Folder in $Folders) {
$FolderName = (get-item "$Folder").Name $FolderName = (get-item "$Folder").Name
"⏳ Step $Step/$($NumFolders + 3): Pulling 📂$FolderName... " "⏳ Step $Step/$($NumFolders + 2) - Pulling 📂$FolderName... "
& git -C "$Folder" pull --recurse-submodules --jobs=4 & git -C "$Folder" pull --recurse-submodules --jobs=4
if ($lastExitCode -ne "0") { $Failed++; write-warning "'git pull' in 📂$FolderName failed" } if ($lastExitCode -ne "0") { $Failed++; write-warning "'git pull' in 📂$FolderName failed" }