簡體   English   中英

如何使用 REST API 在 TFS Source Control 2015 中移動/重命名文件?

[英]How to Move/Rename a file in TFS Source Control 2015, using the REST API?

我正在嘗試使用 Python 和 TFS REST API 在我們的內部 TFS 上移動文件; 服務器似乎只支持版本 2 之前的 API,但在 MSDN 上我找不到 v4.1 以下版本的任何文檔。

我發布到的 URL 是https://<server>/tfs/<Collection>/<Project>/_apis/tfvc/changesets

目前,我對 post 請求的正確 JSON 正文的最佳猜測如下所示:

{
    "comment": "moved file",
    "changes": [{
        "changeType": "rename",
        "item": {
            "path": "<filepath>",
            "version": 468,
                    "sourceServerItem": "<filepath>"
        }

    }]
}

但我無法獲得比 HTTp 錯誤 400 錯誤請求更進一步的信息,並顯示以下消息

{
  "$id": "1",
  "innerException": null,
  "message": "Exactly one value for PathActions is required.\r\nParameter name: change.SourceServerItem",
  "typeName": "System.ArgumentException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
  "typeKey": "ArgumentException",
  "errorCode": 0,
  "eventId": 0
}

對於我的生活,我在 google 上找不到任何對 PathActions 的引用,這不是針對 git 而不是 tfvc,也不是為該項目提供值的正確方法。

有人可以通過 HTTP 請求重命名/移動 TFVC 上的文件嗎?

我突然想到使用 TFS Web 界面進行重命名並查看瀏覽器發送的請求。

原來這是正確的格式:

{
  "comment": "Moved File",
  "changes": [
    {
      "changeType": 8,
      "sourceServerItem": "<old path>",
      "item": {
        "path": "<new path>",
        "version": 470
      }
    }
  ]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM