Move

Harry immediately moves on to his next task, which is to put the repository into the recommended structure[12].

lottery harry$ mkdir trunk

lottery harry$ svn add trunk
A         trunk

lottery harry$ svn move lottery.c trunk
A         trunk/lottery.c
D         lottery.c

lottery harry$ mkdir branches

lottery harry$ svn add branches
A         branches

lottery harry$ svn st
D       lottery.c
A       trunk
A  +    trunk/lottery.c
A       branches

lottery harry$ svn commit -m "recommended dir structure"
Adding         branches
Deleting       lottery.c
Adding         trunk
Adding         trunk/lottery.c

Committed revision 6.

Ouch. Subversion’s move command (which is also used for rename) appears to be implemented as an add and a delete. This makes me worry that the upcoming merge is not going to go smoothly.

Sally decides having the number 7 as a constant in the code is as ugly as homemade soap. She adds a #define to give it a more meaningful name.

lottery sally$ svn diff
Index: lottery.c
===================================================================
--- lottery.c   (revision 5)
+++ lottery.c   (working copy)
@@ -2,6 +2,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#define LUCKY_NUMBER 7
+
 int calculate_result(int white_balls[5], int power_ball)
 {
     for (int i=0; i<5; i++)
@@ -50,7 +52,7 @@
         return -1;
     }
 
-    if (7 == power_ball)
+    if (LUCKY_NUMBER == power_ball)
     {
         result = result * 2;
     }

And immediately tries to commit the change.

lottery sally$ svn commit -m "use a #define for the lucky number"
Sending        lottery.c
Transmitting file data .svn: Commit failed (details follow):
svn: File not found: transaction '6-8', path '/lottery.c'

But Subversion says “File not found”? What in the Sam Hill is that? Sally tries an update.

lottery sally$ svn update
   C lottery.c
A    trunk
A    trunk/lottery.c
A    branches
Updated to revision 6.
Summary of conflicts:
  Tree conflicts: 1

lottery sally$ svn st
A  +  C lottery.c
      >   local edit, incoming delete upon update

Tree conflict? “Incoming delete upon update”? Sally wonders if she could sneak out for some collard greens.

Subversion failed to merge the changes from Sally’s working copy into the moved file. I was sort of expecting this when I saw earlier that Subversion was showing the move as an add/delete.

Apparently lottery.c has moved into a subdirectory called trunk. Sally remembers discussing this with Harry. So she re-applies her #define changes to the new lottery.c in trunk.

lottery sally$ svn st
A  +  C lottery.c
      >   local edit, incoming delete upon update
M       trunk/lottery.c

Now svn status shows the edits she just made, but it’s still bellyaching about conflicts with the old lottery.c. That file isn’t supposed to exist anymore. Since her changes have now been made in the new lottery.c, she decides to revert her changes to the old one.

lottery sally$ svn revert lottery.c 
Reverted 'lottery.c'

lottery sally$ svn st
?       lottery.c
M       trunk/lottery.c

lottery sally$ rm lottery.c 

That resulted in svn status saying ?, so she just deletes her working copy of the file.

Now diff shows her changes applied to the new copy.

lottery sally$ svn diff
Index: trunk/lottery.c
===================================================================
--- trunk/lottery.c (revision 6)
+++ trunk/lottery.c (working copy)
@@ -2,6 +2,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#define LUCKY_NUMBER 7
+
 int calculate_result(int white_balls[5], int power_ball)
 {
     for (int i=0; i<5; i++)
@@ -50,7 +52,7 @@
         return -1;
     }
 
-    if (7 == power_ball)
+    if (LUCKY_NUMBER == power_ball)
     {
         result = result * 2;
     }

And she is ready to commit.

lottery sally$ svn commit -m "use a #define for the lucky number"
Sending        trunk/lottery.c
Transmitting file data .
Committed revision 7.


[12] For Subversion and other tools which represent branches as directories, it is considered good practice to keep the trunk at the top level of the tree alongside a directory into which branches are placed.