Reputation: 1114
Basically what I'm trying to do is download all the source code from a git repository I have hosted in a Visual Studio TFS 2015. With a Powershell script.
The end goal is to develop an automation which would then pick up that code, do some stuff to it and push it to another server.
The thing is, so far the only way I know of obtaining the code is to authenticate to the system and then git clone
the repository. On the other hand, first I don't really want that dependency with git since I only want the files, and second, I don't want to clone the repository, concept-wise.
All in all, any insight as into how to achieve this is appreciated!
Upvotes: 1
Views: 1769
Reputation: 41595
To obtain a file stored within a Git repo in TFS you make use of the items API.
The format of this API looks like this:
https://{instance}/{project}defaultcollection/_apis/git/repositories/{repository}/items?api-version={version}&scopepath={filepath}[&includecontentmetadata={bool}&lastprocessedchange={bool}]
A real-world example of this API (with variable replacement) might look like this:
https:/mytfs:8080/defaultcollection/MyProject/_apis/git/repositories/MyRepo/items?api-version=1.0&scopepath=ReadMe.md
In the above example, I am attempting to download a file named ReadMe.md from a Git repo named MyRepo in the project named MyProject.
You can use the Invoke-RestMethod
Powershell method to get the results.
Upvotes: 2