mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-21 17:38:19 +02:00
Update list-repos.ps1
This commit is contained in:
parent
c5b68daf0e
commit
a79bb3d0eb
@ -3,12 +3,12 @@
|
|||||||
Lists Git repos
|
Lists Git repos
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script lists details of all Git repositories in a folder.
|
This PowerShell script lists details of all Git repositories in a folder.
|
||||||
.PARAMETER ParentDir
|
.PARAMETER parentDir
|
||||||
Specifies the path to the parent directory.
|
Specifies the path to the parent directory (current working directory by default)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./list-repos C:\MyRepos
|
PS> ./list-repos C:\MyRepos
|
||||||
|
|
||||||
Local Repo Latest Tag Branch Status Remote URL
|
Repository Latest Tag Branch Status Remote URL
|
||||||
---------- ---------- ------ ------ ----------
|
---------- ---------- ------ ------ ----------
|
||||||
📂cmake v3.23.0 main ✔️clean git@github.com:Kitware/CMake ↓0
|
📂cmake v3.23.0 main ✔️clean git@github.com:Kitware/CMake ↓0
|
||||||
...
|
...
|
||||||
@ -18,35 +18,35 @@
|
|||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$ParentDir = "$PWD")
|
param([string]$parentDir = "$PWD")
|
||||||
|
|
||||||
function ListRepos {
|
function ListRepos {
|
||||||
$Folders = (Get-ChildItem "$ParentDir" -attributes Directory)
|
$folders = (Get-ChildItem "$parentDir" -attributes Directory)
|
||||||
foreach($Folder in $Folders) {
|
foreach($folder in $folders) {
|
||||||
$FolderName = (Get-Item "$Folder").Name
|
$folderName = (Get-Item "$folder").Name
|
||||||
$LatestTagCommitID = (git -C "$Folder" rev-list --tags --max-count=1)
|
$latestTagCommitID = (git -C "$folder" rev-list --tags --max-count=1)
|
||||||
if ($LatestTagCommitID -ne "") {
|
if ($latestTagCommitID -ne "") {
|
||||||
$LatestTag = (git -C "$Folder" describe --tags $LatestTagCommitID)
|
$latestTag = (git -C "$folder" describe --tags $latestTagCommitID)
|
||||||
} else {
|
} else {
|
||||||
$LatestTag = ""
|
$latestTag = ""
|
||||||
}
|
}
|
||||||
$Branch = (git -C "$Folder" branch --show-current)
|
$branch = (git -C "$folder" branch --show-current)
|
||||||
$RemoteURL = (git -C "$Folder" remote get-url origin)
|
$remoteURL = (git -C "$folder" remote get-url origin)
|
||||||
$NumCommits = (git -C "$Folder" rev-list HEAD...origin/$Branch --count)
|
$numCommits = (git -C "$folder" rev-list HEAD...origin/$branch --count)
|
||||||
$Status = (git -C "$Folder" status --short)
|
$status = (git -C "$folder" status --short)
|
||||||
if ("$Status" -eq "") { $Status = "✔️clean" }
|
if ("$status" -eq "") { $status = "✔️clean" }
|
||||||
elseif ("$Status" -like " M *") { $Status = "⚠️modified" }
|
elseif ("$status" -like " M *") { $status = "⚠️modified" }
|
||||||
New-Object PSObject -property @{'Local Repo'="📂$FolderName";'Latest Tag'="$LatestTag";'Branch'="$Branch";'Status'="$Status";'Remote URL'="$RemoteURL ↓$NumCommits";}
|
New-Object PSObject -property @{'Repository'="📂$folderName";'Latest Tag'="$latestTag";'Branch'="$branch";'Status'="$status";'Remote URL'="$remoteURL ↓$numCommits";}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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" }
|
||||||
|
|
||||||
ListRepos | Format-Table -property @{e='Local Repo';width=19},@{e='Latest Tag';width=18},@{e='Branch';width=20},@{e='Status';width=10},'Remote URL'
|
ListRepos | Format-Table -property @{e='Repository';width=19},@{e='Latest Tag';width=18},@{e='Branch';width=20},@{e='Status';width=10},'Remote URL'
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user