Update list-repos.ps1

This commit is contained in:
Markus Fleschutz 2024-04-19 12:09:00 +02:00
parent 9ae69818cf
commit 04406716db

View File

@ -1,15 +1,15 @@
<# <#
.SYNOPSIS .SYNOPSIS
Lists Git repos Lists Git repositories
.DESCRIPTION .DESCRIPTION
This PowerShell script lists details of all Git repositories in a folder. This PowerShell script lists all Git repositories in a folder with some details.
.PARAMETER parentDir .PARAMETER parentDir
Specifies the path to the parent directory (current working directory by default) Specifies the path to the parent directory (current working directory by default)
.EXAMPLE .EXAMPLE
PS> ./list-repos C:\MyRepos PS> ./list-repos.ps1 C:\Repos
Repository Latest Tag Branch Status Remote URL Local Repo Latest Tag Branch Status Remote Repo
---------- ---------- ------ ------ ---------- ---------- ---------- ------ ------ -----------
📂cmake v3.23.0 main clean git@github.com:Kitware/CMake 0 📂cmake v3.23.0 main clean git@github.com:Kitware/CMake 0
... ...
.LINK .LINK
@ -36,7 +36,7 @@ function ListRepos {
$status = (git -C "$folder" status --short) $status = (git -C "$folder" status --short)
if ("$status" -eq "") { $status = "clean" } if ("$status" -eq "") { $status = "clean" }
elseif ("$status" -like " M *") { $status = "modified" } elseif ("$status" -like " M *") { $status = "modified" }
New-Object PSObject -property @{'Repository'="📂$folderName";'Latest Tag'="$latestTag";'Branch'="$branch";'Status'="$status";'Remote URL'="$remoteURL$numCommits";} New-Object PSObject -property @{'Local Repo'="📂$folderName";'Latest Tag'="$latestTag";'Branch'="$branch";'Status'="$status";'Remote Repo'="$remoteURL$numCommits";}
} }
} }
@ -46,7 +46,7 @@ try {
$null = (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" }
ListRepos | Format-Table -property @{e='Repository';width=19},@{e='Latest Tag';width=18},@{e='Branch';width=20},@{e='Status';width=10},'Remote URL' ListRepos | Format-Table -property @{e='Local Repo';width=19},@{e='Latest Tag';width=18},@{e='Branch';width=20},@{e='Status';width=10},'Remote Repo'
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"