Skip to content

Instantly share code, notes, and snippets.

@glennsarti
Last active July 14, 2016 22:44
Show Gist options
  • Save glennsarti/fa3eaae16f2258b1a404d7b1d7cb363d to your computer and use it in GitHub Desktop.
Save glennsarti/fa3eaae16f2258b1a404d7b1d7cb363d to your computer and use it in GitHub Desktop.
Dev Environment Scripts
@ECHO OFF
RD .bundle /s/q
del Gemfile.lock
bundle install --path .bundle\gems --without system_tests
@ECHO OFF
SETLOCAL
SET /P PROJECT=Enter project name (e.g. puppet):
SET /P PRNUM=Enter PR number (e.g. 12345):
SET REPO=%~dp0%PROJECT%-pr%PRNUM%
ECHO Cleaning...
RD /S /Q "%REPO%" > NUL
ECHO Cloning..
git clone https://github.com/puppetlabs/%PROJECT%.git "%REPO%"
PUSHD "%REPO%"
ECHO Fetching PR...
git fetch origin refs/pull/%PRNUM%/head:pr_%PRNUM%
ECHO Merging PR...
git merge pr_%PRNUM% --no-ff
POPD
$ErrorActionPreference = 'Stop'
$thisDir = $PSScriptRoot
$WorkingDir = Join-Path -path $thisDir -ChildPath 'working'
$myGithubURL = 'https://github.com/glennsarti'
$pupGithubURL = 'https://github.com/puppetlabs'
$repos = @{
"puppetlabs-acl" = @('master','stable')
"puppetlabs-chocolatey" = @('master')
"puppetlabs-dism" = @('master')
"puppetlabs-dsc" = @('master')
"puppetlabs-powershell" = @('master','stable')
"puppetlabs-reboot" = @('master','stable')
"puppetlabs-registry" = @('master','stable')
"puppetlabs-sqlserver" = @('master','stable')
"puppetlabs-wsus_client" = @('master','stable')
}
$repoFilter = '' # blank for everything
$branchFilter = '' # blank for everything
$repos.GetEnumerator() | ? { $_.Key -match $repoFilter } | % {
$repoName = $_.Key
# Clear the working dir
Set-Location $thisDir
if (Test-Path -Path $WorkingDir) { Remove-Item -Path $WorkingDir -Force -Recurse -Confirm:$false | Out-Null }
$repoCloned = $false
# Parse the branch list
$_.Value | ? { $_ -match $branchFilter } | % {
$branchName = $_
if (-not $repoCloned) {
Write-Host "Cloning $repoName ..." -Foreground Green
$repoCloned = $true
& git clone "$($myGithubURL)/$($repoName).git" $WorkingDir
Set-Location $WorkingDir
Write-Host 'Adding upstream...' -Foreground Green
& git remote add upstream "$($pupGithubURL)/$($repoName).git"
Write-Host 'Fetching upstream...' -Foreground Green
& git fetch upstream
}
Write-Host "Checking out the $branchName branch..." -Foreground Green
if ($branchName -ne 'master') {
& git checkout --track "origin/$($branchName)"
} else {
& git checkout master
}
Write-Host "Pulling changes ..." -Foreground Green
& git pull upstream "$branchName" '--ff-only'
Write-Host "Pushing changes back to origin..." -Foreground Green
& git push origin "$branchName"
Write-Host "Done" -Foreground Green
}
}
Set-Location $thisDir
#if (Test-Path -Path $WorkingDir) { Remove-Item -Path $WorkingDir -Force -Recurse -Confirm:$false | Out-Null }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment