Github和Kiln之间的自动同步

9

我是一名前端设计师,没有很强的编程背景。我会做CSS/HTML和一点JavaScript。我们公司的技术团队已经将我们的版本控制从Git(github)转移到了Mercurial(Kiln)。他们这么做的唯一原因是为了使用Kiln的代码审查功能(我们使用Fogbugz并喜欢它)。

问题在于,在我们的版本控制中工作的前端和非开发人员总是出错。我们使用hg-git在Heroku上部署,并习惯了git(从未使用过其他版本控制系统)。 我相信Mercurial是一个很好的工具,但我必须得出结论,我们花费了太多时间处理问题和错误。

我的想法是:有没有办法在github上使用git,然后将所有提交等同步到Mercurial(Kiln)?那么我们就可以使用git,同时拥有Kiln的代码审查功能。

希望你能帮忙。我很想回到我们的技术团队,并提供解决方案;)

4个回答

8
任何你设置的同步都比学习Mercurial本身更容易出错。Git和Mercurial都是很好的工具,非常相似,所以如果你花一个小时阅读它们之间的差异,就能够轻松地在两者之间切换,而不会有任何问题。
不太好的同步选项包括:git-hg、hgit和Mercurial的转换扩展,以及Mercurial对git子仓库的支持,但这些选项都需要对这两个工具有更深入的理解,而使用任何一个工具本身就足够了。
要么让开发人员切换回去,要么让他们为你重写部署内容,但不要在同一家公司中同时使用两种工具。

3

今天,Kiln v3发布了,其中Kiln Harmony具有本地Git支持(事实上,它允许在同一仓库中同时使用Mercurial和Git!)。

作为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
}

2
也许您可以使用 git post-commit 钩子,使用 git-hg 将更改推送/同步到 Kiln?

1
有趣。我一点也不介意被踩,但我也不介意解释 :) 我也是来学习的! - OJ.
1
我也很好奇为什么会有人踩这个回答——从我的角度来看,这个回答比那个“正确”的回答更有帮助。有人能解释一下吗?我刚刚点了个赞... - Derek Bredensteiner
也点赞了……如此简单的解决方案,我竟然还要谷歌一下感到自己很生气。并且它已经抽象化超出了Kiln的范畴(我不使用)。虽然获得反对可能是因为缺乏示例 ;) - Dave Lasley
1
谢谢@DaveLasley,这是我在将东西粘贴到git时继续做的事情。简单性不断证明是一种胜利。 - OJ.

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接