Skip to content

Instantly share code, notes, and snippets.

@createdbyx
Created April 7, 2022 09:42
Show Gist options
  • Save createdbyx/1f582c224ffcb08f6990b3df7094dfb5 to your computer and use it in GitHub Desktop.
Save createdbyx/1f582c224ffcb08f6990b3df7094dfb5 to your computer and use it in GitHub Desktop.
provides a breakdown of git repos in the current path
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
@createdbyx
Copy link
Author

Example usage "& 'P:\PowerShell\Find Unpublished Git Repos.ps1' | ConvertTo-Html | Out-File test.html" to report back a listing of repo status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment