Updated list-repos.ps1

This commit is contained in:
Markus Fleschutz 2024-04-22 12:44:59 +02:00
parent 69b8b3ee4e
commit 81a8082017

View File

@ -2,7 +2,7 @@
.SYNOPSIS .SYNOPSIS
Lists Git repositories Lists Git repositories
.DESCRIPTION .DESCRIPTION
This PowerShell script lists all Git repositories in a folder with some details. This PowerShell script lists all Git repositories in a folder with details such as tag/branch/status/URL.
.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
@ -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 @{'Local Repo'="📂$folderName";'Latest Tag'="$latestTag";'Branch'="$branch";'Status'="$status";'Remote Repo'="$remoteURL$numCommits";} New-Object PSObject -property @{'Local Repo'="📂$folderName";'Latest Tag'="$latestTag";'Branch'="$branch";'Remote Repo'="$remoteURL";'Status'="$status$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='Local Repo';width=19},@{e='Latest Tag';width=18},@{e='Branch';width=20},@{e='Status';width=10},'Remote Repo' ListRepos | Format-Table -property @{e='Local Repo';width=19},@{e='Latest Tag';width=18},@{e='Branch';width=15},'Remote Repo',@{e='Status';width=14}
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"