-
Notifications
You must be signed in to change notification settings - Fork 0
/
gittheworld.ps1
63 lines (51 loc) · 1.69 KB
/
gittheworld.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
$gitAction = $args[0]
$location = $args[1]
$debug = "False"; # "False" or "True"
function Debug($output) {
if ($debug -eq "True")
{
Write-Host $output
}
}
function PerformGitAction($folder, $action) {
Push-Location -Path $folder
Write-Host
Write-Host -ForegroundColor Cyan Performing git $action at $folder
$gitcommand = 'git.exe ' + $action
iex $gitcommand
if ($LastExitCode -eq 0) {
Write-Host -ForegroundColor Green Completed successfully
}
else {
Write-Host -ForegroundColor Red Completed with errors
}
Pop-Location
}
function IsGitRepo ($folder) {
$countOfGitFolders = Get-ChildItem $folder -Force | ?{ $_.PSIsContainer } | ?{$_.Name -eq '.git'} | measure
$result = $countOfGitFolders.Count -gt 0
$result
}
function RecursiveProcess {
param ([string]$folder, [string]$action)
Debug "RecursiveProcess $folder"
$gitFolders = Get-ChildItem "$folder" -Force | ?{ $_.PSIsContainer } | ?{ IsGitRepo($_.FullName) }
$otherFolders = Get-ChildItem "$folder" -Force | ?{ $_.PSIsContainer } | ?{ -Not(IsGitRepo($_.FullName)) }
if ($gitFolders.Count -gt 0) {
Debug "There are git folders " + $gitFolders.Count
foreach ($repo in $gitFolders)
{
Debug "Repo $repo.FullName"
PerformGitAction $repo.FullName $action
}
}
if ($otherFolders.Count -gt 0) {
Debug "There are otherFolders " + $otherFolders.Count
foreach ($childFolder in $otherFolders)
{
Debug "childFolder $childFolder.FullName"
ProcessIt $childFolder.FullName $action
}
}
}
RecursiveProcess -folder $location -action $gitAction