Wednesday, November 27, 2013

TFS: Error deleting Team Project

Recently I needed to cleanup a collection, removing a number of team projects from it. Generally all went fine, but one team project refused to be deleted, saying something like that:

Error logs said not much:
Executing step: 'Delete the team project data from Version Control' VersionControl.DeleteTeamProject (2 of 11)
[Error] Violation of PRIMARY KEY constraint 'PK__#yourLoc__FEE84A3672E9B4C6'. Cannot insert duplicate key in object 'dbo.#yourLocalPendingChanges'. The duplicate key value is (51843).

What I understood from it, is that it failed to delete team project from the source control. Oh well, thought I, I can try to delete from command line. So I did and hit:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE>tf destroy "$/MyProject" /collection:http:\\localhost:8080\tfs\defaultcollection
TF246021: An error occurred while processing your request.
Technical information (for administrator):
SQL Server Error: 2627


At this moment things started looking very dark. I tried of course deleting again from Admin console, and of course with no luck.

But indeed I found the solution :)

I used the destroy command to drop things under source control one by one. Like :
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE>tf destroy "$/MyProject/Subfolder1" /collection:http:\\localhost:8080\tfs\defaultcollection
...
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE>tf destroy "$/MyProject/Subfolder2" /collection:http:\\localhost:8080\tfs\defaultcollection
 ..etc 
At first to folders I hit the same error, but I kept going and then, after some folders got successfully deleted, all others, even those wich were giving error - also got deleted. 

So when all subfolders was deleted I ran again:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE>tf destroy "$/MyProject" /collection:http:\\localhost:8080\tfs\defaultcollection
And it all went good!
So, back to admin console and  delete project again - voila!

I am certain I am not the only one who hit the problem and desperately googled without any result :)
So hope this solution will work for others as well!

Wednesday, November 20, 2013

TFS to Git migration: step by step

It has been some posts about migrating to Git from TFS, unfortunately none of them worked for mas expected.

So, my task was: migrate a source from TFS to Git, preserve all history, but do not include dlls or other heavy files. Last part requires naturally not only removing those files from the latest source, but also removing it from the entire history.
On my way I met some hickups, which I will mention, so the road for others after me can be smooth :)

So, lets start!
You will use GitBash and Git-tf:

1. Install Git-TF. Follow this link and download latest release:  http://gittf.codeplex.com/
 Installation instruction is very easy, I chosen not to use Chocolatey, but changed PATH environment variables, worked perfectly.

2. Start GitBash. If you do not have it - can be downloaded from here

Note! All things from now are done from under GitBash.

Check if git-tf was installed successfully - just type "git tf", it should return usage description of git tf command.

Navigate to the place where you have you Git repositories. I use C:\Git\Sources\Repos folder. So my git promt looks like this now:

3. Clone my TFS source to some temporary Git repo.
git tf clone {collection url} {team project path} {temp repo name} --deep

like this:

Note --deep - that means I want to take history as well.

4. Create Git repository which you will use later as your Git source. So far I will not link it to TFS Git repository, just create it.
git init {repo name}
like this:

get into newly create repository by simply
cd {repo name}
you can see you are in a master branch of your newly created repository:

5. Being there, now pull the source from you temp TFS git to your future Git place:
git pull ../{temp repo name} --depth=100000000

teoretically we could push it to our TFS git already now, but first lets cleanup dlls or other unneeded files, so when we put it to TFS git it is all clean and lightweight.

In my example I had 2 installation files located in folder wix/wixDownloads. So I want to leave those behind.

git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch wix/wixdownloads'
Command works only from the root, so paths must be relative from there.
If I would need to delete only one file, I would type:
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch wix/wixdounloads/wix35.msi' 
It is important it says was rewritten in the end, that means stuff was actually removed. Otherwise - you probably misspell something.

If you type wrong, sometimes you get error "cannot remove directory '..../.git-rewrite" : directory is not empty. Dont panic, just remove it manually.

6. We are almost there! Now just clean up so all deleted files are physically deleted:
git reflog expire --all
git  gc --aggressive --prune
Now you can compare size og original forlder with clone from TFS, and size of cleaned up folder.
If everything is correct, the second one is much smaller!

7. And finally - push up to your TFS git:

git remote add master {your  TFS Git repository address}
git push -u master --all
like this: 

8. Now, when I compare hisoty on my original TFS source to history on my new TFS git source, I see no wixDownloads folder, and even not a corresponding checkin (well, this is because checkin contained JUST this folder, and no other files).



To the left - my new Git repo history, to the right - my original TFS history.

Hope it saves somebodys time!

Update 1: there is a possibility to hit  error when pulling source to the temp repository, if full filenames on temp repository exceed 256 symbols:

 error: unable to create file ...{verylongfullpath}... (Filename too long)

ignoring the error gets us on with being unable to do filter-branch and error:
fatal: Neeeded a single revision

To get around that make sure that the folder name for temp repo is short enough. In my case I just deleted temp repository, created a new one with a very short name and did git pull again.

Monday, November 18, 2013

TFS - customize Features backlog and board

By default Features board shows only work item type Feature. Lets say we have another work item type - Business Request, and we want it to be tretaed same way as Features.

So we need to make changes i categories definition of the process template and include Business Request in Features category.

First, download existing:
witadmin exportcategories /collection:{CollectionAddress} /p:{TeamProjectName} /f:C:\Temp\categories.xml

Now lets edit it:
 

And upload back to server:
witadmin importcategories /collection:{CollectionAddress} /p:{TeamProjectName} /f:C:\Temp\categories.xml

Ok, we can see new work item type available on our Feature backlog:


Next - configure Feature board.
By default it has only 3 columns, and only 2 states to choose from: Active and New. Which was very confusing to me, since our Business Request definitely has more states available.

To make it appear in the list of available States - we need to do changes in process config file. First,
download existing:
witadmin exportprocessconfig /collection:{CollectionAddress} /p:{TeamProjectName} /f:C:\Temp\processConfig.xml

Edit it, so it contains states we want to use:
 
Upload:
witadmin importprocessconfig /collection:{CollectionAddress} /p:{TeamProjectName} /f:C:\Temp\processConfig.xml



Now we can see more States available to map to columns in Features Board:
 

Congratulations!