mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-06-02 08:25:42 +02:00
Update list-repos.ps1
This commit is contained in:
parent
7091f53cf0
commit
eca4d1571f
@ -1,6 +1,6 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Lists Git repositories
|
List Git repositories
|
||||||
.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
|
||||||
@ -8,10 +8,10 @@
|
|||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./list-repos C:\MyRepos
|
PS> ./list-repos C:\MyRepos
|
||||||
|
|
||||||
No Repository Branch Status
|
No Repository Branch LatestTag Status
|
||||||
-- ---------- ------ ------
|
-- ---------- ------ --------- ------
|
||||||
1 cmake main clean
|
1 cmake main v3.23.0 clean
|
||||||
2 opencv main modified
|
2 opencv main 4.5.5 modified
|
||||||
...
|
...
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
@ -21,18 +21,20 @@
|
|||||||
|
|
||||||
param([string]$ParentDir = "$PWD")
|
param([string]$ParentDir = "$PWD")
|
||||||
|
|
||||||
function ListRepos { param([string]$ParentDir)
|
function ListRepos {
|
||||||
[int]$No = 0
|
[int]$No = 0
|
||||||
$Folders = (get-childItem "$ParentDir" -attributes Directory)
|
$Folders = (Get-ChildItem "$ParentDir" -attributes Directory)
|
||||||
foreach ($Folder in $Folders) {
|
foreach ($Folder in $Folders) {
|
||||||
$No++
|
$No++
|
||||||
$Repository = (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)
|
||||||
|
$LatestTag = (git -C "$Folder" describe --tags $LatestTagCommitID)
|
||||||
$Status = (git -C "$Folder" status --short)
|
$Status = (git -C "$Folder" status --short)
|
||||||
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"; 'Status'="$Status"; }
|
New-Object PSObject -property @{ 'No'="$No"; 'Repository'="$Repository"; 'Branch'="$Branch"; 'LatestTag'="$LatestTag"; 'Status'="$Status"; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +44,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='No';width=3},@{e='Repository';width=25},@{e='Branch';width=20},Status
|
ListRepos | Format-Table -property @{e='No';width=3},@{e='Repository';width=25},@{e='Branch';width=20},LatestTag,Status
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user