2023-07-29 10:34:04 +02:00
|
|
|
|
*list-repos.ps1*
|
|
|
|
|
================
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
2023-08-06 11:42:46 +02:00
|
|
|
|
This PowerShell script lists details of all Git repositories in a folder.
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
|
Parameters
|
|
|
|
|
----------
|
2021-11-08 21:36:42 +01:00
|
|
|
|
```powershell
|
2023-07-29 10:15:44 +02:00
|
|
|
|
PS> ./list-repos.ps1 [[-ParentDir] <String>] [<CommonParameters>]
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
|
|
-ParentDir <String>
|
2022-12-04 10:40:18 +01:00
|
|
|
|
Specifies the path to the parent directory.
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
|
Position? 1
|
|
|
|
|
Default value "$PWD"
|
|
|
|
|
Accept pipeline input? false
|
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
|
```
|
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
|
Example
|
|
|
|
|
-------
|
2021-11-08 21:36:42 +01:00
|
|
|
|
```powershell
|
|
|
|
|
PS> ./list-repos C:\MyRepos
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-06 11:42:46 +02:00
|
|
|
|
Repository Latest Tag Branch Updates Status
|
|
|
|
|
---------- ---------- ------ ------- ------
|
|
|
|
|
📂cmake v3.23.0 🌵main ↓0 ✔️clean
|
|
|
|
|
📂opencv 4.5.5 🌵main ↓0 ⚠️modified
|
2021-11-08 21:36:42 +01:00
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
|
Notes
|
|
|
|
|
-----
|
2022-11-17 19:46:02 +01:00
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
|
Related Links
|
|
|
|
|
-------------
|
2021-11-08 21:36:42 +01:00
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
|
Script Content
|
|
|
|
|
--------------
|
2022-11-17 20:05:34 +01:00
|
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2023-08-06 11:42:46 +02:00
|
|
|
|
Lists Git repos
|
2022-11-17 20:02:26 +01:00
|
|
|
|
.DESCRIPTION
|
2023-08-06 11:42:46 +02:00
|
|
|
|
This PowerShell script lists details of all Git repositories in a folder.
|
2022-11-17 20:02:26 +01:00
|
|
|
|
.PARAMETER ParentDir
|
2022-12-04 10:40:18 +01:00
|
|
|
|
Specifies the path to the parent directory.
|
2022-11-17 20:02:26 +01:00
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> ./list-repos C:\MyRepos
|
|
|
|
|
|
2023-08-06 11:42:46 +02:00
|
|
|
|
Repository Latest Tag Branch Updates Status
|
|
|
|
|
---------- ---------- ------ ------- ------
|
|
|
|
|
📂cmake v3.23.0 🌵main ↓0 ✔️clean
|
|
|
|
|
📂opencv 4.5.5 🌵main ↓0 ⚠️modified
|
2022-11-17 20:02:26 +01:00
|
|
|
|
...
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
param([string]$ParentDir = "$PWD")
|
|
|
|
|
|
|
|
|
|
function ListRepos {
|
|
|
|
|
$Folders = (Get-ChildItem "$ParentDir" -attributes Directory)
|
2023-07-29 09:45:37 +02:00
|
|
|
|
foreach($Folder in $Folders) {
|
2023-08-06 11:42:46 +02:00
|
|
|
|
$Repository = (Get-Item "$Folder").Name
|
2022-11-17 20:02:26 +01:00
|
|
|
|
$LatestTagCommitID = (git -C "$Folder" rev-list --tags --max-count=1)
|
2023-08-06 11:42:46 +02:00
|
|
|
|
if ($LatestTagCommitID -ne "") {
|
|
|
|
|
$LatestTag = (git -C "$Folder" describe --tags $LatestTagCommitID)
|
|
|
|
|
} else {
|
|
|
|
|
$LatestTag = ""
|
|
|
|
|
}
|
|
|
|
|
$Branch = (git -C "$Folder" branch --show-current)
|
2023-07-29 09:45:37 +02:00
|
|
|
|
$NumCommits = (git -C "$Folder" rev-list HEAD...origin/$Branch --count)
|
2023-08-06 11:42:46 +02:00
|
|
|
|
$Status = (git -C "$Folder" status --short)
|
|
|
|
|
if ("$Status" -eq "") { $Status = "✔️clean" }
|
|
|
|
|
elseif ("$Status" -like " M *") { $Status = "⚠️modified" }
|
|
|
|
|
New-Object PSObject -property @{'Repository'="📂$Repository";'Latest Tag'="$LatestTag";'Branch'="🌵$Branch";'Updates'="↓$NumCommits";'Status'="$Status";}
|
2022-11-17 20:02:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2022-12-04 10:40:18 +01:00
|
|
|
|
if (-not(Test-Path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
|
|
$Null = (git --version)
|
|
|
|
|
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
|
|
|
|
|
2023-08-06 11:42:46 +02:00
|
|
|
|
ListRepos | Format-Table -property @{e='Repository';width=20},@{e='Latest Tag';width=18},@{e='Branch';width=20},@{e='Updates';width=8},Status
|
2022-11-17 20:02:26 +01:00
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
2022-11-17 20:05:34 +01:00
|
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
2023-08-06 11:42:46 +02:00
|
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of list-repos.ps1 as of 08/06/2023 11:42:29)*
|