Update list-repos.ps1

This commit is contained in:
Markus Fleschutz 2022-11-28 08:41:17 +01:00
parent 61c763a95b
commit 123494e015

View File

@ -4,14 +4,14 @@
.DESCRIPTION .DESCRIPTION
This PowerShell script lists the details of all Git repositories in a folder. This PowerShell script lists the details of all Git repositories in a folder.
.PARAMETER ParentDir .PARAMETER ParentDir
Specifies the path to the parent folder. Specifies the path to the parent directory.
.EXAMPLE .EXAMPLE
PS> ./list-repos C:\MyRepos PS> ./list-repos C:\MyRepos
No Repository Branch LatestTag Status No Repository Branch LatestTag Status
-- ---------- ------ --------- ------ -- ---------- ------ --------- ------
1 cmake main v3.23.0 clean 1 cmake main v3.23.0 clean
2 opencv main 4.5.5 modified 2 opencv main 4.5.5 modified
... ...
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
@ -22,11 +22,10 @@
param([string]$ParentDir = "$PWD") param([string]$ParentDir = "$PWD")
function ListRepos { function ListRepos {
[int]$No = 0 [int]$No = 1
$Folders = (Get-ChildItem "$ParentDir" -attributes Directory) $Folders = (Get-ChildItem "$ParentDir" -attributes Directory)
foreach ($Folder in $Folders) { foreach ($Folder in $Folders) {
$No++ $FolderName = (Get-Item "$Folder").Name
$Repository = (get-item "$Folder").Name
$Branch = (git -C "$Folder" branch --show-current) $Branch = (git -C "$Folder" branch --show-current)
$LatestTagCommitID = (git -C "$Folder" rev-list --tags --max-count=1) $LatestTagCommitID = (git -C "$Folder" rev-list --tags --max-count=1)
$LatestTag = (git -C "$Folder" describe --tags $LatestTagCommitID) $LatestTag = (git -C "$Folder" describe --tags $LatestTagCommitID)
@ -34,12 +33,13 @@ function ListRepos {
if ("$Status" -eq "") { $Status = "clean" } if ("$Status" -eq "") { $Status = "clean" }
if ("$Status" -like " M *") { $Status = "modified" } if ("$Status" -like " M *") { $Status = "modified" }
New-Object PSObject -property @{ 'No'="$No"; 'Repository'="$Repository"; 'Branch'="$Branch"; 'LatestTag'="$LatestTag"; 'Status'="$Status"; } New-Object PSObject -property @{ 'No'="$No"; 'Repository'="$FolderName"; 'Branch'="$Branch"; 'LatestTag'="$LatestTag"; 'Status'="$Status"; }
$No++
} }
} }
try { 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 directory: $ParentDir" }
$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" }
@ -49,4 +49,4 @@ try {
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }