Update list-repos.ps1

This commit is contained in:
Markus Fleschutz 2022-03-28 11:44:20 +02:00
parent 7a11e4705a
commit 6840cd3fbb

View File

@ -1,35 +1,38 @@
<#
.SYNOPSIS
Lists the details of all Git repositories in a folder
Lists Git repositories
.DESCRIPTION
This PowerShell script lists the details of all Git repositories in the given folder.
This PowerShell script lists the details of all Git repositories in a folder.
.PARAMETER ParentDir
Specifies the path to the parent folder.
.EXAMPLE
PS> ./list-repos C:\MyRepos
Repository Branch Status
------ ------ ------
cmake main clean
opencv master clean
No Repository Branch Status
-- ---------- ------ ------
1 cmake main clean
2 opencv main modified
...
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz / License: CC0
Author: Markus Fleschutz | License: CC0
#>
param([string]$ParentDir = "$PWD")
function ListRepos { param([string]$ParentDir)
[int]$No = 0
$Folders = (get-childItem "$ParentDir" -attributes Directory)
foreach ($Folder in $Folders) {
$No++
$Repository = (get-item "$Folder").Name
$Branch = (git -C "$Folder" branch --show-current)
$Status = (git -C "$Folder" status --short)
if ("$Status" -eq "") { $Status = "clean" }
if ("$Status" -like " M *") { $Status = "modified" }
New-Object PSObject -property @{ 'Repository'="$Repository"; 'Branch'="$Branch"; 'Status'="$Status"; }
New-Object PSObject -property @{ 'No'="$No"; 'Repository'="$Repository"; 'Branch'="$Branch"; 'Status'="$Status"; }
}
}
@ -39,7 +42,7 @@ try {
$Null = (git --version)
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
ListRepos | format-table -property Repository,Branch,Status
ListRepos | format-table -property @{e='No';width=3},@{e='Repository';width=25},@{e='Branch';width=20},Status
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"