mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-22 20:51:17 +01:00
Update build-repos.ps1, clone-repos.ps1, fetch-repos.ps1, and
pull-repos.ps1
This commit is contained in:
parent
ddb6484a9d
commit
0cdf5ec9a1
@ -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
|
||||
}
|
||||
}
|
@ -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" }
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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" }
|
||||
|
Loading…
Reference in New Issue
Block a user