Update (with merge)

Meanwhile, Sally is fixin’ to go ahead and add a feature that was requested by the sales team: If the user chooses the lucky number 7 as the red ball, the chances of winning are doubled. Since she is starting a new task, she decides to begin with pull and update to make sure she has the latest code.

lottery sally$ vv pull
Pulling from http://server.futilisoft.com:8080/repos/lottery:
Pulling... Done.                                                               

lottery sally$ vv update

lottery sally$ vv parents
Parents of pending changes in working copy:

    revision:  5:ee2493eac8e7fc751e2b57a87a3768a192770ae3
      branch:  master
         who:  harry
        when:  2011/05/31 10:25:47.532 -0500
     comment:  merge
      parent:  4:7290fd8b3372dfecf5622dec12284d602553258e
      parent:  3:7414ae0aa096674df94e6f3e142e893709ff3ac6

Then she implements the lucky 7 feature in two shakes of a lamb’s tail by adding just a few lines of new code to main().

lottery sally$ vv diff
=== ================
===   Modified: File @/lottery.c
--- @/lottery.c e3d1f5b0034e4d190e76b993e67d3e2bd24072ed
+++ @/lottery.c 2011/05/31 15:27:06.000 +0000
@@ -44,6 +44,11 @@
 
     int result = calculate_result(white_balls, power_ball);
 
+    if (7 == power_ball)
+    {
+        result = result * 2;
+    }
+
     printf("%d percent chance of winning\n", result);
 
     return 0;

And commits her change. And pushes it too.

lottery sally$ vv commit -m "lucky 7"

    revision:  6:d494106a9a796e4887aa8de464d825aa76a59a0b
      branch:  master
         who:  sally
        when:  2011/05/31 10:27:31.083 -0500
     comment:  lucky 7
      parent:  5:ee2493eac8e7fc751e2b57a87a3768a192770ae3

lottery sally$ vv push
Pushing to http://server.futilisoft.com:8080/repos/lottery:
Pushing... Done.                                                               

Meanwhile, Harry has realised his last change had a bug. He modified calculate_result() to return -1 for invalid arguments but he forgot to modify the caller to handle the error. As a consequence, entering a ball number that is out of range causes the program to behave improperly.

lottery harry$ ./a.out 61 2 3 4 5 42
-1 percent chance of winning

The percent chance of winning certainly can’t be a negative number, now can it? So Harry adds an extra check for this case.

lottery harry$ vv diff
=== ================
===   Modified: File @/lottery.c
--- @/lottery.c e3d1f5b0034e4d190e76b993e67d3e2bd24072ed
+++ @/lottery.c 2011/05/31 15:28:08.000 +0000
@@ -44,6 +44,12 @@
 
     int result = calculate_result(white_balls, power_ball);
 
+    if (result < 0)
+    {
+        fprintf(stderr, "Invalid arguments\n");
+        return -1;
+    }
+
     printf("%d percent chance of winning\n", result);
 
     return 0;

And proceeds to commit and push the fix.

lottery harry$ vv commit -m "propagate error code"

    revision:  6:dc13f09452dbc1e24d2ad68b1fba917ef1856b61
      branch:  master
         who:  harry
        when:  2011/05/31 10:28:33.769 -0500
     comment:  propagate error code
      parent:  5:ee2493eac8e7fc751e2b57a87a3768a192770ae3

lottery harry$ vv push
vv: Error 234 (sglib): The branch needs to be merged.

Blimey! Sally must have pushed a new changeset already. Harry once again needs to pull and merge to combine Sally’s changes with his own.

lottery harry$ vv pull
Pulling from http://server.futilisoft.com:8080/repos/lottery:
Pulling... Done.                                                               

lottery harry$ vv heads

    revision:  7:d494106a9a796e4887aa8de464d825aa76a59a0b
      branch:  master
         who:  sally
        when:  2011/05/31 10:27:31.083 -0500
     comment:  lucky 7
      parent:  5:ee2493eac8e7fc751e2b57a87a3768a192770ae3

    revision:  6:dc13f09452dbc1e24d2ad68b1fba917ef1856b61
      branch:  master
         who:  harry
        when:  2011/05/31 10:28:33.769 -0500
     comment:  propagate error code
      parent:  5:ee2493eac8e7fc751e2b57a87a3768a192770ae3
lottery harry$ vv merge
1 updated, 0 deleted, 0 added, 1 merged, 1 unresolved

The merge didn’t go quite as smoothly this time. Harry wonders if anyone would notice if he were to take the Wumpty down to the pub. Apparently there was a conflict. Harry decides to open up lottery.c in his editor to examine the situation.

...
    int result = calculate_result(white_balls, power_ball);

<<<<<<< Baseline: BASELINE~lottery.c: /Users/harry/lottery/.sgdrawer/t/merge_2011...
    if (result < 0)
    {
        fprintf(stderr, "Invalid arguments\n");
        return -1;
    }

=======
    if (7 == power_ball)
    {        
        result = result * 2;
    }

>>>>>>> Other: OTHER~lottery.c: /Users/harry/lottery/.sgdrawer/t/merge_2011...
    printf("%d percent chance of winning\n", result);

    return 0;
...

Veracity has included both Harry’s code and Sally’s code with conflict markers to delimit things. What we want is to include both blocks of code. Sally’s new code can simply be included right after Harry’s error checking.

...
    int result = calculate_result(white_balls, power_ball);

    if (result < 0)
    {
        fprintf(stderr, "Invalid arguments\n");
        return -1;
    }

    if (7 == power_ball)
    {
        result = result * 2;
    }

    printf("%d percent chance of winning\n", result);

    return 0;
...

That should take care of the problem. Harry compiles the code to make sure and then commits the merge.

lottery harry$ vv commit -m "merge"
vv: Error 202 (sglib): Cannot commit with unresolved merge issues.

Crikey! Now what? Harry fixed the conflict in lottery.c but Veracity doesn’t seem to know that.

lottery harry$ vv resolve list
Unresolved contents conflict on File: @/lottery.c
  Baseline Path: @/lottery.c
  Problem: Merge couldn't generate the item's contents.
  Cause(s):
    Edit/Edit: Changes to item's contents in different branches conflict.
  Possible Contents: (use 'view' or 'diff' to examine)
    ancestor
    baseline
    other
    merge:   automatically merged from 'baseline' and 'other' with ':merge'
    working

Ah yes. Harry realises that he forgot to tell Veracity that he had resolved the conflict. He uses resolve to let Veracity know that the problem has been dealt with.

lottery harry$ vv resolve accept working lottery.c
Accepted 'working' value for 'contents' conflict on File:
  @/lottery.c

lottery harry$ vv resolve list

There, that looks much better. Harry tries again to commit the merge.

lottery harry$ vv commit -m "merge"

    revision:  8:817b33a44fd16f268c6bd0f75b95aaf32e461554
      branch:  master
         who:  harry
        when:  2011/05/31 10:29:50.892 -0500
     comment:  merge
      parent:  7:d494106a9a796e4887aa8de464d825aa76a59a0b
      parent:  6:dc13f09452dbc1e24d2ad68b1fba917ef1856b61

And then to retry the push.

lottery harry$ vv push
Pushing to http://server.futilisoft.com:8080/repos/lottery:
Pushing... Done.                                                               

That’s put paid to that.