Automated sync between Github and Kiln

浪子不回头ぞ 提交于 2019-12-03 12:19:55

Any synchronization you set up is going to be more error prone than just learning Mercurial. Git and Mercurial are both great tools, and very similar, so if rather than going at it piecemeal task-by-task you spend a good hour reading about the differences you'll be able to switch back and forth without any problem.

Not-great options for synchronization are: git-hg, hgit, and Mercurial's convert extension, and Mercurial's support for git subrepositories, but you'll regret any of them because they'll require a greater understanding of both tools than using either of them alone would.

Either make the developers switch back or make them rewrite your deploy stuff for you, but don't bother straddling within the same company.

Today Kiln v3 was launched with Kiln Harmony which has native Git support (in fact, it allows both Mercurial and Git on the same repos!).

As a fan of Mercurial, I wrote a script to sync a Kiln Repo periodically with GitHub so I can host my code on GitHub but still use only Mercurial on a daily basis.

The latest version of the PowerShell function is available as a Gist, but I've pasted the current version here for convenience too.

<#
.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
}

Perhaps you could use a git post-commit hook to push/sync your changes to Kiln using git-hg?

You could also set up a Custom Web Hook in Kiln to synchronize to Git from Kiln.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!