Thursday, October 29, 2015

Visual Studio 2013 Git source control meltdown

By Steve Endow

I admit that I'm probably at least 50% responsible for my own mess in this case, but it was an interesting and educational journey (aka a harrowing few hours).  This is my cautionary tale.

I created a project in Visual Studio 2010 back in April for a client that is on GP 2010. Since Visual Studio 2010 doesn't have native Git support, I jumped through all of the hoops and somehow figured out all of the convoluted steps to add get Git working with VS 2010.  I was proud of myself and thought I had it working well.  Let's just say I wasn't quite the superhero I thought I was.


6 months later, the client is now upgrading to GP 2015, so I needed to upgrade the project to GP 2015.  No problem, that should take maybe an hour tops, right?

Except that this is a Project Accounting integration, and I didn't want to install and configure GP 2015 with PA on my old GP 2010 server.  No problem, I've got a GP 2015 server with PA configured, so I'll just use the magic of Git to clone my source code repository and start development on the GP 2015 PA machine, which also has Visual Studio 2013.

I clone my repository and I'm feeling confident.  I update the references for GP 2015, update the project version, and I'm feeling proud.  Until I try and compile.  I get an error that a method isn't valid.  Hmmm.

I check the method, and see that it's in a different class.  I go to open the class...and...it isn't in my project. Ummmm.  That's odd.

I double and triple check, and the class is definitely not in the project.  I login to Bitbucket and check the code online, and the class isn't there either.  So how could I have written code, that works, that references a method in a class that doesn't exist?  Seems unlikely.

I then login to my old GP 2010 PA server and check the old project.  Behold, the class is in the project.  That's pretty strange, since I'm pretty good about committing my code regularly, and definitely when I prepare a release.

So I attempt to re-commit the old GP 2010 project using the Git Extensions tools with Visual Studio 2010.  No matter what I try, the class will not show up on Bitbucket.  Since I haven't yet learned Git command line kung fu, I'm stuck.  With VS 2013, I've seen an issue where a file randomly ended up in the "Untracked Files" section, but I wasn't able to find anything similar in this case on VS 2010.

So I go with Plan B: Copy the class from the old server to my new server, and rely on VS 2013 to get it committed to the branch.  Easy peasy, right?

So I do that, and it gets checked in and things are looking peachy.  I then create a new GP 2015 branch and start re-upgrading the project.  All done, for the second time, with my updates, I commit and push my changes.  I then try and switch back to my master branch...and it all goes downhill again.

I received an error while switching between branches.  Unfortunately I didn't screen shot that error, but after that happened, I was stuck in git branch purgatory.  VS thought I was in my GP 2015 branch, but the code was all from my old master branch.  And if I tried to switch branches, I would get errors like these.



After fighting these for an hour, I vented on Twitter and much to my surprise, I received a response from Buck Hodges, the Microsoft Director of Engineering for Visual Studio Online.  He recommended making sure I was on VS 2013 Update 5, and also strongly recommended VS 2015 for its improved TFS and Git functionality.

I downloaded and installed VS 2013 Update 5 and was eventually able to get around the "there are uncommitted changes" error, but I just wasn't able to get back to a valid version of my GP 2015 branch.

So, after several hours wasted, I did what I should have done earlier and started from scratch.  I copied the entire VS 2010 project from my old server, created a brand new Git repository, checked everything in using VS 2013, created a new GP 2015 branch, and made all of my changes...for the third time.

The new repository is now fine--just like every other new repo I've created with VS 2013.  I don't know what all I did wrong, but I am pretty sure that my problems started with Git on VS 2010.  I'll never do that again since I know that I just don't have the Git "skillz" to dig myself out of a hole.

The only small consolation is that I'm not the only person who has experienced this issue.  I found a few threads on Stack Overflow that let me know I wasn't the first person to blaze this trail.

Thankfully my projects are pretty simple, so as long as I have a good copy of the code, I'm usually able to scrap a repository and start from scratch.

Good luck, and always try to have a backup of that source code...

Steve Endow is a Microsoft MVP for Dynamics GP and a Dynamics GP Certified IT Professional in Los Angeles.  He is the owner of Precipio Services, which provides Dynamics GP integrations, customizations, and automation solutions.

You can also find him on Google+ and Twitter



No comments: