Last active
December 14, 2015 20:39
-
-
Save DanTup/5145885 to your computer and use it in GitHub Desktop.
Scripts to sync a GitHub repo to Kiln to allw GitHub contributions without using Git (use Hg on your Kiln repos!).
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
<# | |
.SYNOPSIS | |
Script to sync a GitHub repo to Kiln to allw GitHub contributions without using Git (use Hg on your Kiln repos!). | |
.DESCRIPTION | |
Create a branch repo in Kiln specifically for for the GitHub sync and run this PS script periodically (PoSh v3 | |
scheduled jobs make this easy). | |
Merge the GitHub branch repo (using Hg!) into your main repo periodically, then push back to the GitHub branch | |
once done. This will be sync'd back to GitHub when the script next runs. | |
Avoid simultaneous changes in the GitHub repo and the Kiln GitHub branch repo, as we don't want the automated | |
script merging (esp. as they could conflict). | |
.EXAMPLE | |
Sync-GitRepositories ` | |
"$kilnBase/Misc/Group/NewSyncTest-GitHub.git" ` | |
"$githubBase/NewSyncTest.git" ` | |
"$tempSyncBase\Scripted" | |
#> | |
function Sync-GitRepositories | |
{ | |
param( | |
[Parameter(Mandatory)] | |
[string]$gitRepo1, | |
[Parameter(Mandatory)] | |
[string]$gitRepo2, | |
[Parameter(Mandatory)] | |
[string]$tempSyncPath, | |
[string]$gitExecutable | |
) | |
# If we weren't given a path to git, assume it's in the path. | |
if (!$gitExecutable) | |
{ $gitExecutable = "git" } | |
# Clone the Kiln Github branch repo if we haven't already got a copy. | |
if (!(Test-Path $tempSyncPath)) | |
{ | |
& $gitExecutable clone $gitRepo1 $tempSyncPath | Out-Default | |
Push-Location $tempSyncPath | |
# Add a remote for the GitHub repo that we're syncing with. | |
& $gitExecutable remote add github $gitRepo2 | Out-Default | |
} | |
else | |
{ | |
Push-Location $tempSyncPath | |
} | |
# Fetch changes from the Kiln GitHub branch repo and merge them in. | |
# Note: Use FastForward-Only to avoid merging (this is automated!), if changes are made to | |
# both GitHub and Kiln GitHub branch simultaneously, we'll have to manually resolve it. | |
# Errors from this script should be emailed to the user! | |
# Note: Always use -q because Git writes progress to STDERR! #WTF | |
& $gitExecutable fetch origin -q | Out-Default | |
& $gitExecutable merge origin/master --ff-only -q | Out-Default | |
# Repeat the process with any changes from GitHub. | |
& $gitExecutable fetch github -q | Out-Default | |
& $gitExecutable merge github/master --ff-only -q | Out-Default | |
# Push changes back to both Kiln GitHub branch repo and GitHub repo. | |
& $gitExecutable push origin : -q | Out-Default | |
& $gitExecutable push github : -q | Out-Default | |
Pop-Location | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment