Update clone-repos.ps1 and pull-repos.ps1

This commit is contained in:
Markus Fleschutz 2022-08-06 14:25:55 +02:00
parent 23fb20eb1a
commit 6fa8cbbeff
2 changed files with 14 additions and 12 deletions

View File

@ -1,6 +1,6 @@
<# <#
.SYNOPSIS .SYNOPSIS
Clones 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 folder.
.PARAMETER folder .PARAMETER folder
@ -23,7 +23,7 @@ try {
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 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
$Table = Import-CSV "$PSScriptRoot/../Data/git-repos.csv" $Table = Import-CSV "$PSScriptRoot/../Data/git-repos.csv"

View File

@ -1,6 +1,6 @@
<# <#
.SYNOPSIS .SYNOPSIS
Pulls updates for all repos in a folder Pulls updates for Git repositories
.DESCRIPTION .DESCRIPTION
This PowerShell script pulls updates for all Git repositories in a folder (including submodules). This PowerShell script pulls updates for all Git repositories in a folder (including submodules).
.PARAMETER ParentDir .PARAMETER ParentDir
@ -18,21 +18,23 @@ 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" } "⏳ Step 1 - Searching for Git executable..."
& git --version
$Null = (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" }
$Folders = (get-childItem "$ParentDir" -attributes Directory) "⏳ Step 2 - Checking folder..."
$NumFolders = $Folders.Count if (-not(Test-Path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" }
$ParentDirName = (get-item "$ParentDir").Name
"Found $NumFolders subfolders in 📂$ParentDirName... "
[int]$Step = 1 $Folders = (Get-ChildItem "$ParentDir" -attributes Directory)
$NumFolders = $Folders.Count
$ParentDirName = (Get-Item "$ParentDir").Name
"⏳ Step 3 - Found $NumFolders subfolders in 📂$ParentDirName... "
[int]$Step = 4
[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): Pulling 📂$FolderName... " "⏳ Step $Step/$($NumFolders + 3): 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" }