Search code examples
visual-studiotfstfvc

Using TFS command line tf.exe how can I copy a repo to a folder location of my choice?


I have stared using TFVC for my MSVS 2015 C++ project. I am used to command line repos like git/svn, where I can simply do a checkout/clone, etc... and copy the files to any folder I like.

So, I have checked out my workspace to a mapped location (c:\myworkspace) via the MSVS2015 GUI. But now I want to to run my auto test script, which will copy the latest files from the repo to the current directory (e.g. c:\autorun). The auto test script builds and tests and generates results etc... But I don't want it to just over-write what I have in my workspace in case someone else has added a change.

I want it to go to a different folder of my choice.

In Git I would just navigate to the folder (cd c:\autorun) and then do git clone <repo-path>. But I can't see how this is possible with TFVC's workspaces.

So far I have started to modify my script that worked with git to get this:

' Clean any existing files:
rmdir /S /Q <projname>

' Checkout project
tf checkout <projname> /recursive

' Do other stuff (build test etc...)

But this only works in my c:\workspace - and I don't want to delete/overwrite my local changes.


Solution

  • You can create a new (temporary) workspace using

    cd temp
    md newfolder
    tf vc workspace /new ...
    tf vc workfold /map $/Project/Folder c:\temp\newfolder
    cd newfolder
    tf vc get . /recursive
    tf workspace /delete
    

    Or you can use the little utility written by Neno Loje, TfsExport.

    Update From OP

    Assuming that I start in the folder that I want to extract my projects into. I used the following:

    tf dir shows the repos I have:

    D:\sandbox\tfs-test > tf dir
    $/:
    $tfsRepo1 
    $tfsRepo2
    $tfsRepo3 
    

    I just want the first two repos:

    tf vc workspace /new /noprompt cit
    tf vc get tfsRepo1 /recursive
    tf vc get tfsRepo2 /recursive
    

    Then to tidy up:

    tf workspace /delete cit /noprompt
    rmdir /S /Q tfsRepo1 
    rmdir /S /Q tfsRepo2
    

    Note the use of /noprompt in various places so that there is no user interaction required.