Skip navigation
The Australian National University

Mercurial Exercise

This page outlines a simple exercise that explores most of the mercurial skills that you are expected to use in COMP1110. This exercise was demonstrated in lecture 10. If you have not seen the lecture, I strongly recommend you watch it. If you get yourself into trouble doing this exercise, you may find it helpful to look at the lecture again. In the lecture I performed the role of all three characters (Alice, Bob and Cindy). You should try to do this exercise in the lab with your group members. If there are only two people in the group, you should be able to adapt the exercise by delegating Cindy's activities to Alice (so you just have Alice and Bob).

  1. The exercise starts with everyone having cloned the group repo.
  2. Alice does the following (with the others watching...):
    • Create a new package, hgtest.
    • Create two new classes, Main (which has a main method), and A which just something simple (like a toString() method.
    • Add both files to mercurial
    • Commit, being sure to set the committer's name appropriately
    • Push
  3. Bob does the following (without co-ordinating with Cindy):
    • Pull and update (check box in pull dialogue allows both to happen together)
    • View project history ("Team...", "Show History"), and see Alice's work.
    • Create a new class, B which just does something simple.
    • Commit, setting committer's name appropriately (the commit dialog will allow you to select the class if you did not do an "Add" before the commit).
    • Do not push the change yet (imagine Bob gets interrupted before pushing).
  4. Cindy does the following (without co-ordinating with Bob):
    • Pull and update (check box in pull dialogue allows both to happen together)
    • View project history ("Team...", "Show History"), and see Alice's work.
    • Create a new class, C which just does something simple.
    • Commit, setting committer's name appropriately (the commit dialog will allow you to select the class if you did not do an "Add" before the commit).
    • Push the changes.
  5. Bob now does the following:
    • Try to push and see an error message giving you the option to either intentionally push a new head, or merge. We will merge in the following steps.
    • Pull and note warning about conflict.
    • View history ("Team...", "Show History")
    • Note that Cindy's commit is above the one in bold, which is where you are.
    • Right click on Cindy's conflicting commit, and select Merge, merging the selected (Cindy) with the current (Bob)
    • You may add something to the commit message that comes up.
    • Push your changes.
  6. Alice and Cindy pull and update, so now everyone should be in the same state. View history to ensure that this is so ("Team...", "Show History")
  7. Bob now conducts an experiment, but doesn't want to mess things up for Alice and Cindy (because it may not pan out), so he used a branch:
    • Add a new branch named "Bob's Experiment" ("Team...", "Add Branch...")
    • Make some change to class B, commit that change.
    • Make another change to class B, commit that change.
    • Push your changes
  8. Everyone does the following concurrently:
    • Pull and update.
    • View history.
    • Ensure that you are on the most recent changeset that is on the default branch (i.e. not on Bob's experimental branch). The changeset you are on will be marked in bold. If you followed all of the steps, it should have been the changeset where Bob did a merge (right before he made the branch). If you're on the wrong changeset, select the correct one, right click your mouse and choose "Switch Repository to Selected Changeset".
    • Now everyone should edit the main method of Main and add a line such as A a = new A(), changed suitably to reflect the author (eg B for Bob and C for Cindy).
    • Commit (but don't yet push) your change
  9. Alice pushes her changes. There should be no error.
  10. Bob now tries to push his change, but will find a problem that he must now resolve.
    • Try to push
    • You should get an error message, which you should reads (you will resolve the problem by merging).
    • Pulls and update, and note an error message stating that a conflict needs to be resolved.
    • Selects Alice's changeset, right click and select "Merge Current with Selected".
    • You should see a window that explains that there's an unresolved conflict.
    • Double double-clicks the "unresolved" conflict and find a split window with Bob's code on the right and the head on the left.
    • Click the icon between the two panes, to move the change to the head. Edit the change (inside the red box on left) to your satisfaction then save.
    • Right-click "unresolve" and declare it "resolved" (it is important that you successfully saved in the step above, otherwise you've not actually resolved the problem).
    • Push your resolved changes
  11. Cindy now tries to push her change, but will run into the same problem as Bob.
    • Try to push
    • You should get an error message, which you should reads (you will resolve the problem by merging).
    • Pulls and update, and note an error message stating that a conflict needs to be resolved.
    • Selects Bob's most recent changeset changeset, right click and select "Merge Current with Selected".
    • You should see a window that explains that there's an unresolved conflict.
    • Double double-clicks the "unresolved" conflict and find a split window with Bob's code on the right and the head on the left.
    • Click the icon between the two panes, to move the change to the head. Edit the change (inside the red box on left) to your satisfaction then save (the main file should now have contributions from all three in it).
    • Right-click "unresolve" and declare it "resolved" (before you do this, it is important that you successfully saved in the step above, otherwise you've not actually resolved the problem).
    • Push your resolved changes
  12. Everyone pulls and updates and should see the Main file with all three contributions.

Updated:  24 August 2012 / Responsible Officer:   JavaScript must be enabled to display this email address. / Page Contact:   JavaScript must be enabled to display this email address.