Mercurial与Team Foundation Server的实际使用?

时间:2010-02-25 04:27:56

标签: tfs mercurial

我的商店使用TFS&除了缺少本地存储库提交/恢复之外,它通常对此感到满意。我自己开始在本地使用Mercurial来帮助管理较小的更改块,然后将它们发布到TFS。我看到Subversion有一个'bridge'组件,如果中央VCS是Subversion,它可以自动启用它。我没有为Team System找到一个。这鼓励了我,其他人已经将DVCS与CVCS系统集成在一起。

(1)有人知道吗?我有点怀疑它(快速搜索没找到任何东西)。

(2)是否有人以这种方式使用Mercurial / TFS?如果是,您可以分享您的经验吗?我特别希望了解在通过Mercurial进行重大活动后提交给TFS的问题可能出现的问题。

到目前为止,这似乎是一个完全双赢,只有我使用了几天 - 但我知道足够的话,认为它就是那么容易。

8 个答案:

答案 0 :(得分:53)

答案 1 :(得分:9)

如果你没有坚持mercurial,那么我一直在使用一个名为git-tfs的甜蜜的git / tfs集成项目。它与git-svn非常相似,但是从TFS推送/拉取。请查看http://github.com/spraints/git-tfs

答案 2 :(得分:5)

@Eric,您在lostechies的帖子最有帮助。使用VS2010,我必须在推送脚本中的 tftp online 命令中添加 / diff / deletes 选项,以便更改和删除文件签入TFS。最初,当文件被删除(从工作中) hg update 时,我从推送中收到错误 “无法删除 FileXyz :访问被拒绝” 我安装了MakeWritable.py扩展名,但只有在打开文件时才会删除。所以我添加了对 attrib 的调用以从项目中的所有文件中删除READ-ONLY,然后将其恢复(不包括.hg文件夹)我还添加了 / diff 选项,以便通过MD5校验和检测差异,而不是依赖于READ-ONLY属性。现在似乎工作正常。

=====FILE: push.ps1=====
$projName = "TicTacToeCMMI"
$tftp = "C:\Program Files\Microsoft Team Foundation Server 2010 Power Tools\TFPT.exe"
$tf = "C:\Program Files\Microsoft Visual Studio 10.0\Common7\ide\tf.exe"

hg push
cd ..\$projName-tfs  
"Syncing -tfs workspace with TFS server"  
&$tftp scorch /noprompt /exclude:.hg',_Resharper*',*.user  
"Making all files in -tfs writable"
attrib -R /S /D *
"Updating -tfs with latest push from Mercurial"
hg update -C -y
attrib +R /S /D *
attrib -R /S /D .hg\*
"Resyncing Mercurial changes with TFS Server"  
&$tftp online /adds /deletes /diff /exclude:'.hgignore,.hg,bin,obj,*.ps1,_Resharper*,*.lnk,*.user,*.suo,*.vspscc'  
"Checkin"  
&$tf checkin  
cd ..\$projName-working  
cmd /c pause  

====FILE: pull.ps1=====
$projName = "TicTacToeCMMI"
$tf = "C:\Program Files\Microsoft Visual Studio 10.0\Common7\ide\tf.exe"
$username = cmd /c set USERNAME
$username = $username.SubString($username.IndexOf("=")+1)

function pull {
    cd ..\$projName-tfs
    &$tf get
    hg commit -A -m "from tfs" --user $username
    cd ..\$projName-working
    hg pull --rebase
}
pull  
cmd /c pause  

我有一些PowerShell脚本的学习曲线,我以前没用过。对于像我这样的其他人来说,脚本是使用这样的快捷方式运行的:

TARGET: C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe C:\dev\TicTacToeCMMI-working\push.ps1
START IN: C:\dev\TicTacToeCMMI-working

我在我的任务栏上放了快捷键,所以只需点击一下即可向/从TFS推/拉

答案 3 :(得分:3)

我知道有些人在Subversion网桥上使用了hgsubversion。我不知道它有多好用,我从来没有使用过TFS。

据我所知,没有比使用TFS更“原生”的桥梁 - > Subversion Bridge - > hgsubversion,但我也听说它运作得相当好。我对TFS的理解非常有限,这表明它的内部模型应该与Subversion类似,因为hgsubversion可以很好地工作。

答案 4 :(得分:2)

如果您希望能够使用DVCS和TFS,我认为最好的方法是为TFS安装SVNBridge,并使用Bazaar,即AFAIK唯一的DVCS很容易与SVN集成,既然你的TFS现在看起来像一个SVN,你就会神奇地获得Bazaar / TFS集成

答案 5 :(得分:2)

这是我用过TFS& amp;的一个PowerShell脚本。汞柱。要使用您需要在TFS文件夹中创建一个hg存储库(将文件从TFS提交到其中),克隆此存储库并处理新存储库。一旦开心,你就可以运行" hgtfs.ps1 push"将更改从您的mercurial存储库推回到TFS。

hgtfs.ps1:

param([parameter(Position=0, Mandatory=$true)][string] $action)

$HGDirectory = Get-Location
$TfsDirectory = @(hg paths | where-object { $_.StartsWith("default = ") })[0].SubString(10)

# Pull from TFS
function pull
{
    # Todo pull changes one by one brining who did it and the comment into HG
    # tf history . /recursive /format:brief /noprompt /version:300~1000 /sort:ascending
    # tf properties . /recursive

    # Add the changes from TFS into the TFS HG repository
    Set-Location $TfsDirectory
    tf get . /recursive
    hg commit -A -m "Update from TFS"  

    # Pull / merge the changes from TFS's HG repository
    Set-Location $HGDirectory
    hg pull
    hg merge --tool internal:fail
    hg commit -m "Merged from TFS"

    ""
    "The you have the following conflicts which need resolving"
    hg resolve -l | write-host -foregroundcolor "red"
    #thg commit
}

# Push to TFS
function push 
{
    Set-Location $HGDirectory
    hg push
    Set-Location $TfsDirectory

    $FilesModified = @()
    $FilesRenamed = @{} # Key: old file name .... Val: new file name
    $FilesRemoved = @()
    $FilesAdded = @()

    # Work out what changes have taken place
    "Calculating the changes which have been made in HG..."
    tfpt scorch /exclude:.hg,*.user | out-null
    $AllChanges = hg status --rev .:tip -A 
    for($i = 0; $i -lt $AllChanges.length ; $i++)
    {
        $type = $AllChanges[$i].SubString(0, 2)
        $fileName = $AllChanges[$i].SubString(2)

        switch($type)
        {
            "M " # Modified files  
                { 
                    $FilesModified += $fileName
                } 

            "A " # New Files
                {  
                    $nextType = $null
                    $nextFileName = $null
                    if($AllChanges.length -gt ($i+1))
                    {
                        $nextType = $AllChanges[$i+1].SubString(0, 2)
                        $nextFileName = $AllChanges[$i+1].SubString(2)                
                    }

                    if($nextType -eq "  ")
                    {
                        # we have a rename
                        $FilesRenamed[$nextFileName]=$fileName
                        $i++
                    }
                    else
                    {
                        # we're adding the file
                        $FilesAdded += $fileName
                    }
                 }

            "R " # Removed
                {
                    if($FilesRenamed.ContainsKey($fileName))
                    {
                        continue
                    }

                    $FilesRemoved += $fileName
                }

            "C " # Same 
                { 
                    continue 
                }

            default 
                { 
                    "Unknown HG status line: "+$AllChanges[$i] 
                    return -1
                }
        }
    }

    # perform the TFS operations 
    "Renaming files in TFS..."
    foreach($file in $FilesRenamed.Keys) {   
        tf checkout $file | out-null
        tf rename $file $FilesRenamed[$file] | out-null
    }

    "Checking out for edit in TFS..."
    foreach($file in $FilesModified) { tf checkout $file | out-null }

    "Removing files from TFS..."
    foreach($file in $FilesRemoved) { tf delete $file | out-null }

    # perform the Mercural update
    "Pulling changes out of HG...."
    hg update --rev .:tip --clean

    # perform any POST TFS operations
    "Adding new files to TFS..."
    foreach($file in $FilesAdded) { tf add $file }

    "Cleaning up..."
    tfpt uu /noget
    tf checkin
}


if ($action -eq "push") { push }
elseif ($action -eq "pull") { pull }
else { "Unknown action ... please supply 'push' or 'pull'" }

# return to our starting point
Set-Location $HGDirectory

答案 6 :(得分:2)

我只是组建了一个小工具HgTfs,它试图完成同步Mercurial和TFS存储库的目标。它非常简单,并且只有三个命令:clone,pull和push。这是我的Bitbucket回购:

https://bitbucket.org/thepretender/hgtfs

还有一篇博客文章描述了工作流程和使用场景(实际上,维基页面只是此博客条目的一部分):

http://www.olegtarasov.me/Post/2013/07/Mercurial-to-TFS-bridge-(hgtfs)

代码很苛刻,但它似乎完成了工作。我真的很感激任何反馈或分叉:)

答案 7 :(得分:1)

我努力让它发挥作用。我可以通过svnbridge让Git和TFS一起玩(link)但是我无法通过svnbridge工作,这让我感到沮丧。如果你设法让它工作让我知道,因为我个人更喜欢mercurial而不是git(尽管两者都很棒)

相关问题