mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-16 17:51:28 +01:00
Update list-repos.ps1
This commit is contained in:
parent
61c763a95b
commit
123494e015
@ -4,14 +4,14 @@
|
||||
.DESCRIPTION
|
||||
This PowerShell script lists the details of all Git repositories in a folder.
|
||||
.PARAMETER ParentDir
|
||||
Specifies the path to the parent folder.
|
||||
Specifies the path to the parent directory.
|
||||
.EXAMPLE
|
||||
PS> ./list-repos C:\MyRepos
|
||||
|
||||
No Repository Branch LatestTag Status
|
||||
-- ---------- ------ --------- ------
|
||||
1 cmake main v3.23.0 clean
|
||||
2 opencv main 4.5.5 modified
|
||||
No Repository Branch LatestTag Status
|
||||
-- ---------- ------ --------- ------
|
||||
1 cmake main v3.23.0 clean
|
||||
2 opencv main 4.5.5 modified
|
||||
...
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
@ -22,11 +22,10 @@
|
||||
param([string]$ParentDir = "$PWD")
|
||||
|
||||
function ListRepos {
|
||||
[int]$No = 0
|
||||
[int]$No = 1
|
||||
$Folders = (Get-ChildItem "$ParentDir" -attributes Directory)
|
||||
foreach ($Folder in $Folders) {
|
||||
$No++
|
||||
$Repository = (get-item "$Folder").Name
|
||||
$FolderName = (Get-Item "$Folder").Name
|
||||
$Branch = (git -C "$Folder" branch --show-current)
|
||||
$LatestTagCommitID = (git -C "$Folder" rev-list --tags --max-count=1)
|
||||
$LatestTag = (git -C "$Folder" describe --tags $LatestTagCommitID)
|
||||
@ -34,12 +33,13 @@ function ListRepos {
|
||||
if ("$Status" -eq "") { $Status = "clean" }
|
||||
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 {
|
||||
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)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
@ -49,4 +49,4 @@ try {
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user