【发布时间】:2019-01-17 02:53:27
【问题描述】:
对于主分支中的文件,我可以使用以下 URL - http://tfsserver:8080/tfs/DefaultCollection/TFSProject/_apis/git/repositories/GitRepo/items?path=FilePath&api-version=4.1
但是如果我需要从分支下载文件怎么办?
附言
我非常清楚我可以克隆一个 git 存储库。我特别需要 REST API。
编辑 1
所以,我尝试了以下代码:
$Url = "http://tfsserver:8080/tfs/DefaultCollection/code/_apis/git/repositories/xyz/itemsbatch?api-version=4.1"
$Body = @"
{
"itemDescriptors": [
{
"path": "/Bootstrap.ps1",
"version": "shelve/vsts",
"versionType": "branch"
}]
}
"@
Invoke-RestMethod -UseDefaultCredentials -Uri $Url -OutFile $PSScriptRoot\AutomationBootstrapImpl.ps1 -Method Post -ContentType "application/json" -Body $Body
成功了,但是生成的文件不是我所期望的:
{"count":1,"value":[[{"objectId":"ceb9d83e971abdd3326d67e25b20c2cb1b4943e2","gitObjectType":"blob","commitId":"d4a039914002613e775f6274aee6489b244a42a7","path":"/bootstrap.ps1","url":"http://tfsserver:8080/tfs/DefaultCollection/code/_apis/git/repositories/xyz/items/bootstrap.ps1?versionType=Branch&version=shelve%2Fvsts&versionOptions=None"}]]}
但是,它提供了我可以用来从分支获取文件的 URL - http://tfsserver:8080/tfs/DefaultCollection/code/_apis/git/repositories/xyz/items/bootstrap.ps1?versionType=Branch&version=shelve%2Fvsts&versionOptions=None
那么,我们开始吧:
$Url = "http://tfsserver:8080/tfs/DefaultCollection/code/_apis/git/repositories/xyz/items/bootstrap.ps1?versionType=Branch&version=shelve/vsts"
Invoke-RestMethod -UseDefaultCredentials -Uri $Url -OutFile $PSScriptRoot\AutomationBootstrapImpl.ps1
它按预期工作。但是我还是不知道这个API方法叫什么名字?
【问题讨论】:
标签: git azure-devops