2017-10-11 68 views
1

我試圖通過TFS GIT REST API將子模塊添加到我在TFS上的git回購,但是到目前爲止沒有運氣。我創建了新的存儲庫並將.gitmodules添加到存儲庫,但無法弄清楚如何添加子模塊文件夾/引用。TFS Git Rest Api - 如何添加子模塊?

這是我試圖構建的名爲「SomeTools」的.gitignore,.gitmodules和子模塊的初始提交的原始請求。

POST http://tfs:8080/tfs/My_Collection/My_Projekt/_apis/git/repositories/TestRepo/pushes?api-version=2.0 HTTP/1.1 
Accept: */* 
Content-Type: application/json 
Host: tfs:8080 
Content-Length: 7213 

{ 
    "refUpdates": [ 
         { 
          "name": "refs/heads/develop", 
          "oldObjectId": "0000000000000000000000000000000000000000" 
         } 
        ], 
    "commits": [ 
        { 
         "changes": [ 
             { 
              "newContent": { 
                   "content": *.suo\r\n", 
                   "contentType": "rawtext" 
                  }, 
              "changeType": "add", 
              "item": { 
                 "path": "/.gitignore" 
                } 
             }, 
             { 
              "newContent": { 
                   "content": "[submodule \"SomeTools\"]\n\tpath = SomeTools\n\turl = http://tfs:8080/tfs/My_Collection/My_Projekt/_git/SomeTools\n", 
                   "contentType": "rawtext" 
                  }, 
              "changeType": "add", 
              "item": { 
                 "path": "/.gitmodules" 
                } 
             }, 
             { 
              "newContent": { 
                   "content": "198abf113d8baf48aa55ab1897b30fdb7b23c4cc", 
                   "contentType": "rawtext" 
                  }, 
              "changeType": "add", 
              "item": { 
                 "path": "/SomeTools", 
                 "versionType": "commit" 
                } 
             } 
            ], 
         "comment": "Initial commit." 
        } 
       ] 
} 

回答

1

我們不能做到這一點由pushes REST API,它可以創建一個新的分支,但不是子模塊。

似乎您手動創建存儲庫並添加.gitmodules文件,如果是,那麼您還需要手動創建submodule文件夾/引用,然後提交>推送到Git服務器。

最簡單的方法是運行git submodule add命令來添加Git的子模塊:

假設你有2個Git倉庫:

http://server:8080/tfs/DefaultCollection/TeamProjectName/_git/Repo1 
http://server:8080/tfs/DefaultCollection/TeamProjectName/_git/Repo2 

添加git的子模塊爲Repo1:

git clone http://server:8080/tfs/DefaultCollection/TeamProjectName/_git/Repo1 

git submodule add http://server:8080/tfs/DefaultCollection/TeamProjectName/_git/Repo2 

然後提交更改並推送到Git存儲庫。

enter image description here

+0

@Wojciech Markowski有你在上面的解決方法解決這個問題?任何更新? –

+0

不幸的是,我找不到通過rest api解決問題的方法。我必須使用git local repository來添加子模塊,並按照上面所述將它推送到TFS,但是我希望web api將在短時間內得到改進以支持此功能。 –