Created
April 7, 2022 09:42
-
-
Save createdbyx/1f582c224ffcb08f6990b3df7094dfb5 to your computer and use it in GitHub Desktop.
provides a breakdown of git repos in the current path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GitData | |
{ | |
[string]$Folder | |
[string]$Branch | |
[int]$Modifications | |
[int]$Additions | |
[int]$Deletions | |
[int]$Untracked | |
[int]$Renamed | |
} | |
$drive = Get-Location | |
$gitFolders = (Get-ChildItem $drive -Attributes Directory+Hidden -ErrorAction SilentlyContinue -Filter ".git" -Recurse | Select-Object -Property FullName) | |
$results = New-Object System.Collections.ArrayList | |
foreach ($entry in $gitFolders) | |
{ | |
$e = $entry.FullName -replace ".{4}$" | |
Set-Location $e | |
git remote | Out-Null | |
[array]$status = git status -sb | |
$c = New-Object -TypeName GitData | |
$c.Folder = $e | |
foreach ($x in $status) | |
{ | |
$firstTwo = $x.Substring(0, 2) | |
switch ($firstTwo) | |
{ | |
'##' { | |
$c.Branch = $x | |
} | |
' M' { | |
$c.Modifications += 1 | |
} | |
' A' { | |
$c.Additions += 1 | |
} | |
' D' { | |
$c.Deletions += 1 | |
} | |
' R' { | |
$c.Renamed += 1 | |
} | |
'M ' { | |
$c.Modifications += 1 | |
} | |
'A ' { | |
$c.Additions += 1 | |
} | |
'D ' { | |
$c.Deletions += 1 | |
} | |
'R ' { | |
$c.Renamed += 1 | |
} | |
'??' { | |
$c.Untracked += 1 | |
} | |
} | |
} | |
$results.Add($c) | Out-Null | |
} | |
$results | Sort-Object -Property @{ Expression = { $_.Modifications + $_.Additions + $_.Deletions + $_.Renamed }; Descending = $true } | |
Set-Location $drive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage "& 'P:\PowerShell\Find Unpublished Git Repos.ps1' | ConvertTo-Html | Out-File test.html" to report back a listing of repo status