2023-10-31 12:33:36 +01:00
|
|
|
|
<#
|
2021-09-28 20:03:03 +02:00
|
|
|
|
.SYNOPSIS
|
2023-07-30 11:00:07 +02:00
|
|
|
|
Lists Git repos
|
2021-09-28 20:03:03 +02:00
|
|
|
|
.DESCRIPTION
|
2023-07-30 11:00:07 +02:00
|
|
|
|
This PowerShell script lists details of all Git repositories in a folder.
|
2024-03-20 13:27:17 +01:00
|
|
|
|
.PARAMETER parentDir
|
|
|
|
|
Specifies the path to the parent directory (current working directory by default)
|
2021-09-28 20:03:03 +02:00
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> ./list-repos C:\MyRepos
|
2021-09-28 20:06:15 +02:00
|
|
|
|
|
2024-03-20 13:27:17 +01:00
|
|
|
|
Repository Latest Tag Branch Status Remote URL
|
2023-11-04 10:20:47 +01:00
|
|
|
|
---------- ---------- ------ ------ ----------
|
2023-08-23 17:29:15 +02:00
|
|
|
|
📂cmake v3.23.0 main ✔️clean git@github.com:Kitware/CMake ↓0
|
2021-09-28 20:06:15 +02:00
|
|
|
|
...
|
2021-09-28 20:03:03 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-01-29 12:47:46 +01:00
|
|
|
|
.NOTES
|
2022-03-28 11:44:20 +02:00
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-09-28 20:03:03 +02:00
|
|
|
|
#>
|
|
|
|
|
|
2024-03-20 13:27:17 +01:00
|
|
|
|
param([string]$parentDir = "$PWD")
|
2021-09-28 20:03:03 +02:00
|
|
|
|
|
2022-03-28 12:12:26 +02:00
|
|
|
|
function ListRepos {
|
2024-03-20 13:27:17 +01:00
|
|
|
|
$folders = (Get-ChildItem "$parentDir" -attributes Directory)
|
|
|
|
|
foreach($folder in $folders) {
|
|
|
|
|
$folderName = (Get-Item "$folder").Name
|
|
|
|
|
$latestTagCommitID = (git -C "$folder" rev-list --tags --max-count=1)
|
|
|
|
|
if ($latestTagCommitID -ne "") {
|
|
|
|
|
$latestTag = (git -C "$folder" describe --tags $latestTagCommitID)
|
2023-07-30 18:47:46 +02:00
|
|
|
|
} else {
|
2024-03-20 13:27:17 +01:00
|
|
|
|
$latestTag = ""
|
2023-07-30 18:47:46 +02:00
|
|
|
|
}
|
2024-03-20 13:27:17 +01:00
|
|
|
|
$branch = (git -C "$folder" branch --show-current)
|
|
|
|
|
$remoteURL = (git -C "$folder" remote get-url origin)
|
|
|
|
|
$numCommits = (git -C "$folder" rev-list HEAD...origin/$branch --count)
|
|
|
|
|
$status = (git -C "$folder" status --short)
|
|
|
|
|
if ("$status" -eq "") { $status = "✔️clean" }
|
|
|
|
|
elseif ("$status" -like " M *") { $status = "⚠️modified" }
|
|
|
|
|
New-Object PSObject -property @{'Repository'="📂$folderName";'Latest Tag'="$latestTag";'Branch'="$branch";'Status'="$status";'Remote URL'="$remoteURL ↓$numCommits";}
|
2021-09-28 20:03:03 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2024-03-20 13:27:17 +01:00
|
|
|
|
if (-not(Test-Path "$parentDir" -pathType container)) { throw "Can't access directory: $parentDir" }
|
2021-09-28 20:03:03 +02:00
|
|
|
|
|
2024-03-20 13:27:17 +01:00
|
|
|
|
$null = (git --version)
|
2021-09-28 20:03:03 +02:00
|
|
|
|
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
|
|
|
|
|
2024-03-20 13:27:17 +01:00
|
|
|
|
ListRepos | Format-Table -property @{e='Repository';width=19},@{e='Latest Tag';width=18},@{e='Branch';width=20},@{e='Status';width=10},'Remote URL'
|
2021-09-28 20:03:03 +02:00
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
2022-04-13 12:06:32 +02:00
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-09-28 20:03:03 +02:00
|
|
|
|
exit 1
|
2023-07-30 11:00:07 +02:00
|
|
|
|
}
|