In this third article in the series about using version control, I'll cover using version control in a team, which is where it becomes one of the most essential tools to get to grips with in software development.
In the first article, I was trying to write a small program in the jPoetry.NET language. I had written this:
I walked around by myself for a bit, feeling a bit lonely,
like a cloud floating over the vales and hills,
then suddenly saw some flowers;
they were cool.
Now, my boss is worried that I have slipped behind schedule (and hasn't read The Mythical Man Month), so she assigns Billy Wordsvalue to help me. Fortunately, he's pretty good at the syntax and semantics of this programming language and we get on with our work. Billy and I are not pair poetry writing (we haven't read Extreme Programming Explained, or Pair Programming). We work on separate computers with our code checked out on our local hard disks.
In order to check in my changes, when I'm working in a team do the following sequence:
1) run all tests
2) update, including doing any manual integration needed if there are conflicting updates (more about this later)
3) run all tests again if there were any updates. I like to run the tests before updating (i.e. step 1) because if the tests fail after I've updated then I want to be sure that the problem is because of something I've updated rather than because the tests would have failed even without an update. The tests have to run quickly if you want to check-in frequently.
4) I like to check through what I'm about to commit because I've got a terrible memory, and might leave some dodgy System.out, or worse, in the code.
5) update again - in case someone has checked-in while I've been running the tests and reading through the changes (having fast version control system is also important when checking in frequently.
6) if there were no incoming changes then commit1, otherwise start from (2) again
1I like the people making the check in to include their initials in the check in comment, so it's easy to tell who to ask if you don't understand some code or changes to some code. You can't rely on the login details when people are pair programming or when you have people swapping machines/logins as happens on many Agile projects.
Billy edits the code as follows:
I walked around by myself for a bit, feeling a bit lonely,
like a cloud that floats on high o'er vales and hills,
then suddenly saw some flowers;
they were cool.
He goes through steps 1-6 and commits his changes (he finds that there are no incoming changes so his check in is easy). At the same time, I've been working and have edited the code as follows:
I walked around by myself for a bit, feeling a bit lonely,
like a cloud floating over the vales and hills,
then suddenly saw some flowers;
by a puddle,
they were cool.
Now I am ready to check in, so I do the steps:
1) "run all tests" - they pass
2) "update, including doing any manual integration needed" - I do an update, and subversion merges Billy's changes into my file, in this case without any conflicts as we have changed different lines. In practice, even on teams of a dozen developers, you don't get many conflicts. The result is:
I walked around by myself for a bit, feeling a bit lonely,
like a cloud that floats on high o'er vales and hills,
then suddenly saw some flowers;
by a puddle,
they were cool.
3) "run all tests again" - they pass
4) I check to see what changes I've made. Because I've done an update, the only changes shown are the ones I've made, not the changes that Billy made.
5) "update again" - Billy hasn't checked in since (1) so there are no more incoming changes
6) "if there were no incoming changes then commit" - so I commit.
Meanwhile, Billy has continued to work. He continues to edit:
I wandered lonely as a cloud
that floats on high o'er vales and hills,
then suddenly saw some flowers;
they were cool.
He goes through steps 1-6 again. The result of his update and check in leaves the poem as:
I wandered lonely as a cloud
that floats on high o'er vales and hills,
then suddenly saw some flowers;
by a puddle,
they were cool.
I edit:
I walked around by myself for a bit, feeling like a lost slug,
or a cloud that floats on high o'er vales and hills,
then suddenly saw some flowers;
by a puddle,
they were cool.
Now when I try to update, I get a warning that there is a conflict. Billy and I have both changed the first two lines. In cases like this, subversion can't work out how to merge the changes itself - it takes understanding to resolve the conflict. I manually resolve the conflicts and end up with:
I wandered around, feeling like a lost slug, lonely as a cloud
that floats on high o'er vales and hills,
then suddenly saw some flowers;
by a puddle,
they were cool.
which I think merges the best of Billy's work with mine. I tell subversion that the merge conflict is resolved.
I continue with steps (3)-(6) and check in.
We continue to work and end up with:
Mary had a little lamb,
its fleece was white as snow,
everywhere that Mary went,
the lamb was sure to go.
It's a funny old world.
Posted by ivan at October 8, 2005 7:24 PM