Last active
July 23, 2018 17:42
-
-
Save crossan007/6694e30399c47ea9e6c5c6d011672ff9 to your computer and use it in GitHub Desktop.
Convert All Top-Level Folders in Git Repository to Independent Repositories
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
# This basically creates a fork-bomb where each forked process is splitting out one top-level folder | |
$MaxSimultaneousJobs = $(Get-WmiObject –class Win32_processor).NumberOfCores * .5 | |
Write-Host "Processing up to $MaxSimultaneousJobs at a time" | |
Get-ChildItem -Directory | Foreach-Object { | |
$FolderName = """$($_.Name)""" | |
$BranchName = $_.Name -Replace(' ','-') | |
while (@(Get-Job -State Running).Count -ge $MaxSimultaneousJobs) { | |
Write-Host "Waiting to process: $BranchName" | |
Start-Sleep -Seconds 300 | |
} | |
Write-Host "Beginning to process: $BranchName" | |
$Command = "git subtree split -P $FolderName -b $BranchName" | |
$scriptBlock = [Scriptblock]::Create($Command) | |
Start-Job -InitializationScript ([scriptblock]::Create("Set-Location $PWD")) -Scriptblock $scriptBlock | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment