Last active
March 31, 2017 22:02
-
-
Save connerk/dc13bddf110b36cad1a1d5d91c6c6f41 to your computer and use it in GitHub Desktop.
Powershell Git Helpers
This file contains 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
function Get-GitRepoStatusRecursing { | |
[CmdletBinding()] | |
Param ( | |
[Parameter(Position=1, | |
ValueFromPipelineByPropertyName=$true)] | |
[string]$directory = (Get-Item -Path ".\" -Verbose).FullName, | |
[string[]]$ignoredFolders = @(".git","node_modules","Past Payrolls","Benefits","_Archive", ` | |
"e-Time Data","Compensation Plans","DCH Pay Plan Files",` | |
"Payroll Additional Functions","Payroll eFiles"), | |
[switch]$showErrors = $false, | |
[switch]$dirtyOnly = $false | |
) | |
$vbose = $PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent | |
if ($showErrors) { | |
$ErrorActionPreference= "Continue" | |
}else{ | |
$ErrorActionPreference= "silentlycontinue" | |
} | |
function recurse ($directory, $stopAt) { | |
Write-Progress -Activity $directory -Status "Please wait..." | |
$dirs = Get-ChildItem $directory -Directory -Force | |
if ($dirs.Name -contains ".git") { | |
$gitStatus = git -C $directory status --short | |
$repo = @($directory, $gitStatus) | |
$global:repos += , $repo | |
if ($vbose) { | |
if (-not($gitStatus)) { | |
if(-not($dirtyOnly)) { Write-Host -f Green "$directory" } | |
} else { | |
Write-Host -f Green "$directory" | |
$gitStatus | |
} | |
} | |
} | |
foreach ($dir in $dirs) { | |
if (-not($stopAt.contains($dir.name))) { | |
recurse $dir.fullName $stopAt | |
} | |
} | |
} | |
$global:repos = @() | |
if ($vbose) {Write-Host "Seeking All Repositories in $directory"} | |
recurse $directory $ignoredFolders | |
if ($vbose) {Write-Host $global:repos.Count "Repositories found"} | |
return [void]$global:repos #{TODO} should fill a variable but not write to screen | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment