Sunday, March 18, 2012

Multiple Users and Merging

Often you will have multiple people working on the same design.  This can lead to an issue where the last one to save a shared file is the "winner" because all their changes walk over everyone else's.  Many version control systems, included SoildWork's PDMWorks, get around this by forcing a check-out/change/check-in procedure where only one user at a time is allowed to change a file.  Obviously Mercurial doesn't work this way because it encourages users to make clones of repositories and then push their changes back.  For situations where multiple users are pushing changes back to a shared repository Mercurial requires users to merge their changes if there are multiple differences between their local clone and the shared repo before committing.

Now, merging is pretty easy if you are working with just text files and TortoiseHg provides tools to help you merge multiple changes.  Issues arise where you are working with binary files (like SolidWorks) because TortoiseHg and Mercurial don't know what tools to use to properly merge them.

Say your team is working on a project and you just made some changes and committed them to your local repository.  Now you want to send those changes to the shared repo so the rest of the team can have them in their designs.
Step 1: Sync with the shared repository and pull any changes.  Follow the directions in this previous post to set up the sync.  If anyone else on the team has pushed changes to the shared repository you should get them, and if they've made changes to files that you've made changes to you should see a branch in the Workbench.

Here you can see that another users has also made changes to i2b-Table-M0001.SLDPRT.  So, the next step is to compare your changes with the changes you pulled in from the other user.

Step 2: Right-click on the tip of the branch and select "Merge with local..."
This will show you the two branches that will be merged.  Click "Next"
TortoiseHg will give you a summary of the merge letting you know that files need to be resolved before committing.  If you click on the resolve link you will see this screen:
This gives you a list of the unresolved files and some buttons for resolve actions on each file.
Mercurial Resolve - Mercurial will attempt to resolve the conflicts, this probably won't work since we're working with binary files
Tool Resolve - this will use the default merge tool to allow you to resolve the conflicts, but none of the tools that come with TortoiseHg know how to handle SolidWorks files.  There may be a solution to this...
Take Local - this will resolve the conflicts by saying the local file is the one you want to keep
Take Other - this will resolve the conflicts by saying the file you pulled in is the one you want to keep
Mark as Resolved - this will mark the file as resolved, basically keeping your local copy
If you want you could open the file from the shared location in SolidWorks, see what changes were made and then open your local file and make the changes.  If you did this then you would use the Mark as Resolved button.  But there may be an easier way.

Right-click in your local repository and select Global Settings.  Look for the Three-way Merge Tool setting and select "internal:dump".
 Now when you are in the resolve window and hit the Tool Resolve button Mecurial will dump out a set of files for the file being resolved.
.base - this is a copy of the file that is parent to the one with changes, so it is the version without either your changes or the other user's changes
.local -  this is a copy of your file
.orig - this is also a copy of your file
.other -  this is a copy of the other user's changes

Step 3: Now, if you add the proper file suffix (.sldprt, .sldasm, .slddrw) to .other you will be able to see the other user's changes and can incorporate them into your local file.  Make sure you are saving the changes over the main file and not one of the .* files, otherwise your changes won't end up in the repository when you commit.  Once you do this you can go back to the resolve window and select Mark as Resolved.  Repeat this for all the unresolved files and make sure to delete all the .* files that were created.

Step 4: Now that you've resolved all the files you can commit the changes to your local repository and push them up to the shared one.  When the other people on your team pull in the changes from the shared repository they will see your merge and get the updated file with both your changes and the one you incorporated from the other user.
I don't mean to make light of resolving changes with SolidWorks.  It can still be a time consuming step to incorporate the other user's changes into the design.  I do think that being able to easily get at the .base file can make this easier allowing you to start from the same point that both you and the other user did when the changes were made.

It may be possible to create a SolidWorks macro to help with all this.  Mercurial has the ability to use custom merge tools and someone could write one that ran a macro which uses the .* files.

All this was done using TortoiseHg 2.2 with Mercurial 2.0

Wednesday, December 1, 2010

More Repositories, Sharing And Global .hgignore

Now that we know how to create repositories it is simple enough to create new ones by right-clicking in the main folder and selecting TortoiseHg - Create Repository Here.
But what about sharing those files with others, including the changes?

Tuesday, November 23, 2010

Making Changes

Last time we looked at setting up Mercurial using TortoiseHg.  Today we'll look at making changes to our design and seeing how Mercurial handles them.


Thursday, November 18, 2010

Getting Started

Okay.  I've been a long time SolidWorks user but have never used a version control system other than the one provided by Windows Explorer and my brain, and that hasn't always been foolproof.  So in a effort to get my designs under control and honor my cheapskate bone I've decided to try one of the open source version control systems to track my designs.  After a little research I've settled on Mercurial because this article that makes distributed version control seem better than the others and TortoiseHg is integrates nicely with Windows.


So, here's how I got started.