今天 Kiln v3 与 Kiln Harmony 一起发布,它具有原生 Git 支持(事实上,它允许 Mercurial 和 Git 在同一个 repos 上!)。
作为 Mercurial 的粉丝,我编写了一个脚本来定期将 Kiln Repo 与 GitHub 同步,这样我就可以在 GitHub 上托管我的代码,但每天仍然只使用 Mercurial。
最新版本的 PowerShell 函数以 Gist 的形式提供,但为了方便起见,我也在此处粘贴了当前版本。
<#
.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
}