Updated List-repos.ps1

This commit is contained in:
Markus Fleschutz 2024-08-22 08:05:00 +02:00
parent bc52eaf3f6
commit 5aa652be29

View File

@ -2,15 +2,15 @@
.SYNOPSIS
Lists Git repositories
.DESCRIPTION
This PowerShell script lists all Git repositories in a folder with details such as latest tag/branch/status/URL.
This PowerShell script lists all Git repositories under a folder with details such as latest tag, branch, remote URL, and status.
.PARAMETER parentDir
Specifies the path to the parent directory (current working directory by default)
.EXAMPLE
PS> ./list-repos.ps1 C:\Repos
PS> ./list-repos.ps1 C:\MyRepos
Local Repo Latest Tag Branch Status Remote Repo
---------- ---------- ------ ------ -----------
📂cmake v3.23.0 main clean 0 git@github.com:Kitware/CMake
REPOSITORY LATEST TAG BRANCH REMOTE URL STATUS
---------- ---------- ------ ---------- ------
📂cmake v3.30.2 master https://github.com/Kitware/CMake clean 0
...
.LINK
https://github.com/fleschutz/PowerShell
@ -36,17 +36,17 @@ function ListRepos {
$status = (git -C "$folder" status --short)
if ("$status" -eq "") { $status = "clean" }
elseif ("$status" -like " M *") { $status = "changed" }
New-Object PSObject -property @{'Local Repo'="📂$folderName";'Latest Tag'="$latestTag";'Branch'="$branch";'Status'="$status";'Remote Repo'="$numCommits $remoteURL"}
New-Object PSObject -property @{'REPOSITORY'="📂$folderName";'LATEST TAG'="$latestTag";'BRANCH'="$branch";'REMOTE URL'="$remoteURL";'STATUS'="$status$numCommits"}
}
}
try {
if (-not(Test-Path "$parentDir" -pathType container)) { throw "Can't access directory: $parentDir" }
if (-not(Test-Path "$parentDir" -pathType container)) { throw "Can't access parent directory at: $parentDir" }
$null = (git --version)
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
ListRepos | Format-Table -property @{e='Local Repo';width=19},@{e='Latest Tag';width=16},@{e='Branch';width=19},@{e='Status';width=10},'Remote Repo'
ListRepos | Format-Table -property @{e='REPOSITORY';width=19},@{e='LATEST TAG';width=16},@{e='BRANCH';width=19},@{e='REMOTE URL';width=47},@{e='STATUS';width=12}
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"