From 0cdf5ec9a1e14285acbfcbb7a7d650c8c6577b16 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Thu, 18 Aug 2022 09:46:16 +0200 Subject: [PATCH] Update build-repos.ps1, clone-repos.ps1, fetch-repos.ps1, and pull-repos.ps1 --- Scripts/build-repos.ps1 | 20 ++++++++++---------- Scripts/clone-repos.ps1 | 13 +++++++------ Scripts/fetch-repos.ps1 | 9 +++++---- Scripts/pull-repos.ps1 | 13 ++++++------- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Scripts/build-repos.ps1 b/Scripts/build-repos.ps1 index fedefcd5..483f5c6d 100755 --- a/Scripts/build-repos.ps1 +++ b/Scripts/build-repos.ps1 @@ -1,16 +1,16 @@ <# .SYNOPSIS - Builds all Git repositories in a folder + Builds Git repositories .DESCRIPTION - This PowerShell script builds all Git repositories in a given folder. + This PowerShell script builds all Git repositories in a folder. .PARAMETER ParentDir - Specifies the path to the folder containing the Git repositories + Specifies the path to the parent folder .EXAMPLE PS> ./build-repos C:\MyRepos .LINK https://github.com/fleschutz/PowerShell .NOTES - Author: Markus Fleschutz / License: CC0 + Author: Markus Fleschutz | License: CC0 #> param([string]$ParentDir = "$PWD") @@ -18,12 +18,12 @@ param([string]$ParentDir = "$PWD") try { $StopWatch = [system.diagnostics.stopwatch]::startNew() - if (-not(test-path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" } - - $Folders = (get-childItem "$ParentDir" -attributes Directory) + $ParentDirName = (Get-Item "$ParentDir").Name + "⏳ Step 1 - Checking parent folder 📂$ParentDirName..." + if (-not(Test-Path "$ParentDir" -pathType container)) { throw "Can't access folder: $ParentDir" } + $Folders = (Get-ChildItem "$ParentDir" -attributes Directory) $FolderCount = $Folders.Count - $ParentDirName = (get-item "$ParentDir").Name - "Found $FolderCount subfolders in 📂$ParentDirName..." + "Found $FolderCount subfolders." [int]$Step = 1 foreach ($Folder in $Folders) { @@ -37,4 +37,4 @@ try { } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" exit 1 -} +} \ No newline at end of file diff --git a/Scripts/clone-repos.ps1 b/Scripts/clone-repos.ps1 index cb8e405b..8998bca3 100755 --- a/Scripts/clone-repos.ps1 +++ b/Scripts/clone-repos.ps1 @@ -22,15 +22,16 @@ try { & git --version 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" } $ParentFolderName = (Get-Item "$FolderPath").Name + "⏳ Step 3 - Checking table in Data/git-repos.csv..." $Table = Import-CSV "$PSScriptRoot/../Data/git-repos.csv" $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]$Skipped = 0 foreach($Row in $Table) { @@ -41,16 +42,16 @@ try { $Step++ if (test-path "$FolderPath/$FolderName" -pathType container) { - "⏳ Step $Step/$($NumEntries + 3) - Skipping 📂$($FolderName) (exists already)..." + "⏳ Step $Step/$($NumEntries + 4) - Skipping 📂$($FolderName) (exists already)..." $Skipped++ continue } 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" if ($lastExitCode -ne "0") { throw "'git clone --branch $Branch $URL' failed with exit code $lastExitCode" } } 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" if ($lastExitCode -ne "0") { throw "'git clone --branch $Branch $URL' failed with exit code $lastExitCode" } } diff --git a/Scripts/fetch-repos.ps1 b/Scripts/fetch-repos.ps1 index 9ff95500..52d2898e 100755 --- a/Scripts/fetch-repos.ps1 +++ b/Scripts/fetch-repos.ps1 @@ -1,6 +1,6 @@ <# .SYNOPSIS - Fetches updates for all Git repositories in a folder + Fetches updates for Git repositories .DESCRIPTION This PowerShell script fetches updates for all Git repositories in a folder (including submodules). .PARAMETER ParentDir @@ -22,11 +22,12 @@ try { & git --version 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) $NumFolders = $Folders.Count - $ParentDirName = (Get-Item "$ParentDir").Name - "⏳ Step 2 - Found $NumFolders subfolders in 📂$ParentDirName..." + "Found $NumFolders subfolders." [int]$Step = 3 foreach ($Folder in $Folders) { diff --git a/Scripts/pull-repos.ps1 b/Scripts/pull-repos.ps1 index 18ad6062..41885c7f 100755 --- a/Scripts/pull-repos.ps1 +++ b/Scripts/pull-repos.ps1 @@ -22,19 +22,18 @@ try { & git --version if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" } - "⏳ Step 2 - Checking folder..." - 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) $NumFolders = $Folders.Count - $ParentDirName = (Get-Item "$ParentDir").Name - "⏳ Step 3 - Found $NumFolders subfolders in 📂$ParentDirName... " + "Found $NumFolders subfolders." - [int]$Step = 4 + [int]$Step = 3 [int]$Failed = 0 foreach ($Folder in $Folders) { $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 if ($lastExitCode -ne "0") { $Failed++; write-warning "'git pull' in 📂$FolderName failed" }