How to export the files under a label from TFS in a script using tf? - version-control

I need a batch script that uses tf to retrieve the directory structure for a label in TFS, something like the equivalent of svn export, while not messing up with my current working workspace.
This is what I managed to come up with:
tf workspace /new TemporaryWorkspace /noprompt
This will create a new workspace, but with the following working folder:
$/: C:\
(considering that I ran the command from C:)
This is not what I want, but "tf workspace /new" doesn't seem to allow specifying the mapping, so I ran this to remove the default mapping:
tf workfold /unmap $/ /workspace:TemporaryWorkspace
then this one to create my desired mapping.
tf workfold /workspace:TemporaryWorkspace /map $/Project/Path C:\Temp\Path
Change the current directory to the local working folder (I don't know of another way to select the current workspace)
PUSHD C:\Temp\Path
Now I can finally retrieve the label and do my stuff with it.
tf get /version:LMyBeautifulLabel
Now the clean up.
tf workspace /delete TemporaryWorkspace /noprompt
Go back
POPD
All these seems a bit too cumbersome for my humble purpose. Is there a simpler way?
Thanks.

Unfortunately, you will need to create a workspace with the proper working folder mappings and then run the get. There's no one-liner alias to set this up for you.
You may be able to get by with creating a longer-lived workspace with the proper working folder mappings that you need not delete, but certainly if you're using this workflow frequently but with different labels or in different locations, creating a new temporary workspace each time probably does make the most sense.
Your best solution here is to either create a command script that executes this workflow or use the little known script functionality of the tf command line client. You can run a tf script by using:
tf #<filename>
or simply using:
tf #
to read from standard input.

Related

How to mirror/synchronize a local workspace folder with the server folder?

I have a folder that regularly gets updated. This folder is a part of a TFS workspace. I need to commit all those changes to the workspace once they occur (add what isn't there, delete what was removed and update what was changed).
Currently, I have a script that runs tf vc folderdiff command on the folder and its server counterpart, parses out the output to get three lists - files that need to be added, deleted and updated. It then manually adds, deletes and updates those files by invoking tf add/delete/checkout on batches of files (trying to add/delete/checkout in one go can cause an error if there are too many files in the list).
There has to be some better way. Is there some kind of tf command where I can tell it, look at this local folder, look at the server folder that is mapped to it and make the server folder look exactly the same? Bonus points if I can specify some kind of filter to exclude certain paths or file names/extensions.
Apparently there exists a tf reconcile command. You can learn more about the syntax here: https://learn.microsoft.com/en-us/azure/devops/repos/tfvc/reconcile-command
Off the top of my head, the following command should do what I want:
tf reconcile [path to folder] /promote /adds /deletes /recursive /noprompt
There is also /exclude that can be used to filter unwanted files, so I get the bonus points too.
Of course I had to stumble upon it right after asking a question...

How to specify workspace to use in command line

I am trying to write a Powershell script where I may need to checkout items into different workspaces. How can I specify in the tf command which workspace to use?
Your best option is to use the tfs workspace command and create a new 'temporary' workspace while your ps script executes.
This only requires you to know the tfs path, you can then map to a local folder and only work with the files you need. At the end of the script you can delete the workspace.
Tfs workspace command
http://msdn.microsoft.com/en-us/library/y901w7se(v=vs.100).aspx

TFS Creating Build script for releases

I want to be able to set up a semi automatic Build script to check out a specific commit from our TFS server to a non generic folder to then cause the code to be built and packaged to enable a release.
I understand how to use the command line, and can script it fine, but its how to create a temporary workspace that will not interfere with the existing workspace on the machine to check the code out into.
I will have to research how to build the solution as well from the commandline but that may not be as hard as this...
You can use the command line tool tf.exe to create a new workspace e.g.:
tf workspace /new workspace_name`;username /collection:http://myserver:8080/tfs/DefaultCollection
You can get work folder mappings by using a template when creating the new workspace. See the /template parameter on tf workspace. Or you can use the tf workfold /map command to create work folder mappings for the new workspace. When you're done, use tf workspace /delete to delete the workspace.

History with diffs embedded

To see the history of each checkin a user has done in a directory tree i can type:
tf history . /recursive /user:name /noprompt /format:detailed
It displays all checkins "name" has performed with checkin comments and paths to the changed files. I want to display, in addition to that, the diff of each affected file. Like /format:extraverbose. Is there a way to have tf do that? If not, how can you create a powershell script that does that for me?
You can disregard things like branches and merges - there are none in the directory tree.
I don't think there's a command line for that right now, maybe you can create a Powershell script using the TFS Powertools CmdLet.
Otherwise you can still make a command line exe using the TFS API, it's easier than one might think. Look at this answer to get the source files of a command line tool that I made for someone.

Check in a file to TFS (command line) withouth a work space

Is it possible to just say to TFS that I have a file (call it Version.txt) and I want it to be checked in at a location (say $/MyProject/MyVersionLocation) and not have any workspace setup for that location?
Something like (pretend Syntax):
tf.exe c:\Version.txt CheckIn $/MyProject/MyVersionLocation /WorkSpaceOverride
If so, how do you do it?
It is not possible to checkin a file without a workspace mapping for that path.
One option would be to use a combination of "tf workspace" and "tf workfold" to dynamically create a workspace before checking in.
For example:
tf workspace /collection:http://server:8080/tfs/Collection /new TempWorkspace /noprompt
tf workfold /collection:<server> /workspace:TempWorkspace /map $/MyProject/MyVersionLocation/Version.txt C:\Version.txt