Delete TFS branch without downloading it - visual-studio-2010

I am trying to delete a branch that has not been downloaded into my workspace via following command.
tf delete /lock:checkout /recursive $/TfsServerName/TfsFolder/Branch
I get following error message:
No matching items found in $/TfsServerName/TfsFolder/Branch in your workspace.
Is there a way to delete a TFS branch without actually downloading it?

you can do a non-recurisve get of only the folder with the "tf get" command. I am not aware that you can delete it when you don't have a local copy of the folder.

Make sure the folder above the branch is mapped to the filesystem, then:
Open up Visual Studio's "Developer Command Prompt"
cd (change directory) into the folder above the branch
and run the following:
tf get .
tf delete /recursive branch-folder
tf checkin
This will do a non-recursive get, mark the whole branch/folder for deletion, then prompt you to enter a message and check in the change.
Should work with VS2012-2015 & TFS 2010 to current. Also tested with Visual Studio Team Services hosted TFS (as of 25th Feb 2016)
With VS2012 / TFS server 2010, the delete command needs /recursive

In the Source Control Explorer you can get the latest version of a branch then cancel it as soon as it starts downloading. That will un-ghost the branch allowing you to delete it through the interface. You'll also have to delete the few files that were downloaded to your local work space. It's a total hack but it's really quick and easy.

In the Source Control Explorer, if you simply map the branch to a local path and hit OK, it will enable the "delete dropdown".

Related

Visual Studio - Source Control Explorer for TFS - how to view which changeset is your local copy

I use Visual Studio 16.4.2 (2019) and TFS.
How to check "where" is my local copy of code (whick changeset I have locally)?
TFS workspace does not contain a property to track differences between local and server changeset versions. As workaround:
You can compare you local and server root folders:
Just periodically update your workspace
If you want to check the changeset number in your workspace, you can use the following history command from the root (top) of your workspace:
tf history . /r /noprompt /stopafter:1 /version:W
Check the follow blog for more information of this command:
https://blogs.msdn.microsoft.com/buckh/2009/01/26/how-to-determine-the-latest-changeset-in-your-workspace/

Finding files that are not checked into repo

Is there an easy way to find files that are not checked into my repository in my Visual Studio project?
In the past, there's been times when I get my code base from the repo only to realize that some files -- for some reason -- had not been checked into the repository.
I recently got a new laptop and downloaded the code for my app onto my new machine. I'm now getting an error when I run the app on the new laptop but on the old one it runs perfectly fine. My first thought was that there were configuration differences between two machines so I downloaded the code into a new folder on the old machine and started having the same error that I'm having on the new laptop. If I run the app from the original folder on the old machine, it runs fine.
This makes me think that I may have some differences in the code between what's on the repo and the original folder. As a result, if I get the code from the repo, I have the error. If I try to check in the code from the original folder on the old laptop, Visual Studio tells me that there's nothing to check in.
So, is there an easy way for me to see if there's any file that is not checked into the repo on my old laptop?
BTW, I'm running Visual Studio 2019 -- with the latest updates/patches -- and my repo is on Azure DevOps and uses TFVC.
Running tf vc status /format:detailed /recursive from a Visual Studio Developer Commandline in your workspace root should give you a good overview of files not checked in and files with pending changes.
C:\Users\JesseHouwing\source\Workspaces\xxx>tf vc status /format:detailed /recursive
-----------------------------------------------------------------------------------------------------------------------
Detected Changes:
-----------------------------------------------------------------------------------------------------------------------
$/xxx/test.txt
User : Jesse Houwing
Date : zaterdag 27 juli 2019 21:20:00
Lock : none
Change : add
Workspace : SHARKIE
Local item : [SHARKIE] C:\Users\JesseHouwing\Source\Workspaces\xxx\test.txt
0 change(s), 1 detected change(s)
It should auto-detect files unless you specify the /nodetectchanges flag.
Or, if your .tfignore file is well specified, you can run tf vc add * /recursive to automatically create a pending change for all files that are currently not under version control. If needed, edit your tfignore file before running the add command. Add /noignore to bypass the ignore file, but that may add bin and obj and packages folders as well, be careful.
tf.exe is hidden deep in the bowels of Visual Studio, easiest way to get access to it is to use the Developer Command Prompt:
My installation has put it here:
C:\Users\JesseHouwing\source\Workspaces\xxx>where tf
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\TF.exe

In TFS, is it possible to create local workspace from a script?

MS' pages talk about using the command-line tf.exe to create a local workspace prior to calling tf get but describe that even from the command-line, a TFS dialog box will be shown.
One of our build scripts, as we move from VSS to TFS, gets a repo into a working copy prior to building. It would be preferable if this script can be run on a 'clean' PC and it automatically creates the local workspaces, or can somehow get a copy without using a workspace (we really need something closer to svn export as no changes are being made). But a dialog box requires we manually set up each machine with local workspaces first.
Is what I want possible?
If you look at the full help tf help workspace, you see:
tf workspace /new [/noprompt] [/template:workspacename[;workspaceowner]]
[/computer:computername] [/comment:("comment"|#commentfile)]
[workspacename[;workspaceowner]]
[/collection:TeamProjectCollectionUrl]
[/permission:(Private|PublicLimited|Public)]
[/login:username,[password]]
As you can see, you can specify /noprompt and all of the parameters that the prompt would collect.
For setting the working folder, you'd use tf workfold:
tf workfold /map serverfolder localfolder
[/collection:TeamProjectCollectionUrl]
[/workspace:workspacename]
[/login:username,[password]]

SVN Post Commit Hook Batch Windows

I have a Windows Server running Visual SVN Server to store our repositories.
Also on that server is our test copy.
I'm trying to set up a simple SVN post-commit hook so it updates that test copy automatically every time I commit something
In Visual SVN in the post-commit hooks I've set up like this
"C:\Program Files (x86)\VisualSVN Server\bin\updatescripts.bat" D:\inetpub\TESTCOPY
Then that batch file has a simple update like this
PATH=%PATH%;"C:\Program Files (x86)\VisualSVN Server\bin\"
svn update %1
If I run the batch file in the server by double clicking on it or from command line works fine.
When committing something from my laptop it freezes and doesn't give me any error and locks the test copy so then I need to go in and run a clean up.
Visual SVN service is running as network service and this aacount has full access to the bin folder and the test copy on the server.
Any idea how to set up a simple svn update post commit hook anyone?
Thanks
Fede
I had a similar problem and it turned out to be that SVN likes paths to use forward slashes instead of backslashes.
Try this:
set MYPATH=%1
:: Transform backslashes to forward slashes
set MYPATH=%MYPATH:^\=/%
svn update %MYPATH%
You're running the svn update command. Exactly what working copy are you trying to update?
The parameter being passed is the Repository's path. This points not to a working directory, but to the directory that contains the Subversion master repository. This is the same directory where your post commit hook is stored.
Subversion hooks do not have access to the user's working directory, so you can't manipulate the user's files. Hook scripts usually should be using svnlook and not svn. By doing this, you prevent yourself from getting into any sort of trouble.
It is possible to update a Subversion working copy on the server, if you know the location:
PATH=%PATH%;"C:\Program Files (x86)\VisualSVN Server\bin\"
set SVN_WORK_DIR=C:\SVN\workdir"
svn update %SVN_WORK_DIR%
However, I wouldn't recommend this because it ties up Subversion. The user who did the commit would have to wait until the update is complete before Subversion returns the control of the prompt back to the user.
After trying a million different things this worked for me...
I put this in my post-commit hook
"C:\Program Files\VisualSVN Server\bin\svn.exe" update "C:\my path\"
where my path is the path to the working copy to be updated
Also I had to change the service to run as local system
That is really not the way you want to do that. What you should do is use something like Jenkins to watch your repository. Jenkins can watch your repository, and it when it changes, update your test copy, kick-off builds, run automated tests, etc.

How to connect to source control server using TF command line utility

I'm trying to run a commands using Tf Command-Line Utility I'm getting errors when trying to connect to TFS server. I'm not sure what tf tool is expecting as far as parameters.
It tells me to connect to workspaces by running tf /collection:TeamProjectCollectionUrl'
To get the TeamProjectCollectionUrl I went into Visual Studio Team Explorer, looked at properties of a project and copied URL property. The url starts with vstfs://
You want to use the standard HTTP or HTTPS URL to specify your project collection. (This is the same URL that's shown in the connection dialog in Visual Studio.) For example:
http://tfs.contoso.com:8080/tfs/DefaultCollection
TFS installs on port 8080 by default, and (beginning in TFS 2010), the name of your project collection is the suffix.
Alternately, you shouldn't need to specify the project collection - if you run the tf resolve command from one of your working folders, it will determine the server information automatically. That is, if you have the workspace mapping:
$/Project/Source -> C:\Work\Source
If your current working directory is C:\Work\Source and run the tf command line client, it should locate your TFS workspace automatically.
1- Add "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE" path into Environment variable path.
2 - Create a batch file (simply copy and modify the below commands and save into file with ext .bat)
CLS
tf get $/Project/Source /recursive /force
Pause
exit
3- Copy .bat file and place into your local Mapped folder and run.

Resources