Git 级联合并

Git 级联合并,git,azure-devops,Git,Azure Devops,VST支持级联合并吗?我们的团队正在寻求从隐藏转换到VST,但我们广泛使用的一个特性是级联合并,而VST似乎不支持级联合并 例如,假设我有release1、release2和development分支。我从Release_1分支并创建一个pull请求以将我的分支与Release_1合并。在Stash中,可以使用语义分支名称使其自动与较新版本合并并开发。在这种情况下,合并到发布版本1将自动触发合并到发布版本2并进行开发 这是否可以在VST中设置,或者需要某种类型的git钩子?级联合并最近不适用于V

VST支持级联合并吗?我们的团队正在寻求从隐藏转换到VST,但我们广泛使用的一个特性是级联合并,而VST似乎不支持级联合并

例如,假设我有release1、release2和development分支。我从Release_1分支并创建一个pull请求以将我的分支与Release_1合并。在Stash中,可以使用语义分支名称使其自动与较新版本合并并开发。在这种情况下,合并到发布版本1将自动触发合并到发布版本2并进行开发


这是否可以在VST中设置,或者需要某种类型的git钩子?

级联合并最近不适用于VST

但有一个用户声音建议VST使用此功能,您可以投票并跟进

目前的解决方法是使用web钩子或CI构建按顺序合并其他分支,正如jessehouwing所提到的

内联Powershell任务 有点像是在问我自己的问题,但我想在一段时间前发布这个,但只是忘记了

下面是我最后编写的内联Powershell任务,用于VSTS中的构建步骤。务必确保在“获取源”步骤中选中“不同步源”。您还应该设置CI触发器,以包括基于语义通配符的分支。在我们的例子中,它是rc/*。您还需要确保选中“允许脚本访问OAuth令牌”

我想我会在这里发布我的解决方案,以防有人在谷歌搜索中偶然发现。它绝对不是完美的,也没有很好的错误处理能力,但它完成了任务

# Change the output of the git commands so that the output doesn't cause the builds to fail even when there are no errors.
$env:GIT_REDIRECT_STDERR = '2>&1'

# Flag that gets set to true if a merge has conflicts
$mergeConflict = $false

# Initialize the empty repository
git init

git config --global user.email "buildAgent@nobody.com"
git config --global user.name "BuildAgent"

# Clone the repository
git clone https://buildAgent:$($env:SYSTEM_ACCESSTOKEN)@YOURDOMAINHERE.visualstudio.com/YOUR/REPO/HERE

cd YOURREPOHERE

# Get the branches that we want to cascade merges through
$versionList = git branch -r --list '*/rc/*'

$versionArray = @()

# Fix up the branch names so they are easier to work with
foreach ($branch in $versionList) {
   $versionArray += $branch.Replace('origin/','').Trim()
}

# Add the Sprint branch to the end of the array
$versionArray += 'Sprint'

# Get the branch that triggered the cascade
$currentBranch = $env:BUILD_SOURCEBRANCH

# Fix up the branch name so it is easier to work with
$currentBranch= $currentBranch.Replace('refs/heads/','')

# Checkout the branch that triggered the cascade
git checkout $currentBranch

# Find the branch in our list of branches that we want to cascade through so that we skip any that we don't want to cascade to.
$currentBranchIndex = $versionArray.indexof($currentBranch)

# For each branch in the array checkout the next version and merge the previous version into it. Add ***NO_CI*** to the commit message so that the push to VSTS does not trigger
# another build which would trigger another cascade. If there is a conflict abort otherwise push the branch after merging.
for ($i=$currentBranchIndex; $i -lt $versionArray.length-1; $i++) 
{ 
    git checkout $versionArray[$i+1]; git merge $versionArray[$i] --no-ff -m "Merge $($versionArray[$i]) to $($versionArray[$i+1]) ***NO_CI***"
    if($LastExitCode -ne 0){
      'conflict merging:  ' + $versionArray[$i] + ' into ' + $versionArray[$i+1]
      $mergeConflict = $true
      break
    }
    else{
      git push origin $versionArray[$i+1]
    }
}


# There was a merge conflict. Create a pull request with the appropriate source and target so that we can resolve the merge conflict.
if($mergeConflict){
      $uri = 'https://YOURDOMAINHERE.visualstudio.com/YOURPROJECTHERE/_apis/git/repositories/REPOIDHERE/pullrequests?api-version=4.1'
      $user = "buildAgent"
      $Base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $User,$env:SYSTEM_ACCESSTOKEN)))
      $params = @{"sourceRefName"="refs/heads/$($versionArray[$i])";
                            "targetRefName"="refs/heads/$($versionArray[$i+1])";
                            "title" = "Automatic Merge Failure";
                            "description" = "There was a merge conflict merging $($versionArray[$i]) into $($versionArray[$i+1])";
                          }
    try{
          Invoke-RestMethod -uri $uri -body ($params|ConvertTo-Json) -method 'Post' -contentType "application/json" -Headers @{Authorization=("Basic {0}" -f 
          $Base64AuthInfo)}
     }
    catch{
        $result = $_.Exception.Response.GetResponseStream()
        $reader = New-Object System.IO.StreamReader($result)
        $reader.BaseStream.Position = 0
        $reader.DiscardBufferedData()
        $responseBody = $reader.ReadToEnd();
        $responseBody
    }

    "##vso[task.complete result=Failed;]DONE"
}

生成配置不支持。但是一个带有一点powershell的CI构建可能会使它成为可能。或者,您可以使用VST中的服务挂钩来触发Azure函数。。