[svnbook commit] r3420 - trunk/src/en/book

codesite-noreply at google.com codesite-noreply at google.com
Fri Feb 6 11:45:32 CST 2009


Author: stsp at elego.de
Date: Fri Feb  6 08:07:04 2009
New Revision: 3420

Modified:
    trunk/src/en/book/ch02-basic-usage.xml

Log:
* src/en/book/ch02-basic-usage.xml
   (svn.tour.treeconflicts.example): New section illustrating how to
    deal with tree conflicts.


Modified: trunk/src/en/book/ch02-basic-usage.xml
==============================================================================
--- trunk/src/en/book/ch02-basic-usage.xml	(original)
+++ trunk/src/en/book/ch02-basic-usage.xml	Fri Feb  6 08:07:04 2009
@@ -2348,7 +2348,271 @@
          problems before committing.</para>

        <!-- TODO: example -->
+    <sect2 id="svn.tour.treeconflicts.example">
+      <title>An example Tree Conflict</title>

+      <para>Suppose a software project you are working currently
+       looks like this:</para>
+
+      <screen>
+$ svn ls -Rv svn://svn.example.com/trunk/
+      4 harry                 Feb 06 14:34 ./
+      4 harry              23 Feb 06 14:34 COPYING
+      4 harry              41 Feb 06 14:34 Makefile
+      4 harry              33 Feb 06 14:34 README
+      4 harry                 Feb 06 14:34 code/
+      4 harry              51 Feb 06 14:34 code/bar.c
+      4 harry             124 Feb 06 14:34 code/foo.c
+</screen>
+
+      <para>Suppose your collaborator Harry has renamed the file
+        <filename>bar.c</filename> to <filename>baz.c</filename>.
+        You are still working on <filename>bar.c</filename> in your
+        working copy, but you don't know yet that the file has
+        been renamed in the repository.</para>
+
+      <para>Suppose the log message to Harry's commit looks like
+        this:</para>
+
+      <screen>
+------------------------------------------------------------------------
+r5 | harry | 2009-02-06 14:42:59 +0000 (Fri, 06 Feb 2009) | 2 lines
+Changed paths:
+   M /trunk/Makefile
+   D /trunk/code/bar.c
+   A /trunk/code/baz.c (from /trunk/code/bar.c:4)
+
+Rename bar.c to baz.c, and adjust Makefile accordingly.
+</screen>
+
+      <para>Suppose the local changes you have made look like this:</para>
+
+      <screen>
+$ svn diff
+Index: code/foo.c
+===================================================================
+--- code/foo.c  (revision 4)
++++ code/foo.c  (working copy)
+@@ -3,5 +3,5 @@
+ int main(int argc, char *argv[])
+ {
+        printf("I don't like being moved around!\n%s", bar());
+-       return 0;
++       return 1;
+ }
+Index: code/bar.c
+===================================================================
+--- code/bar.c  (revision 4)
++++ code/bar.c  (working copy)
+@@ -1,4 +1,4 @@
+ const char* bar(void)
+ {
+-       return "Me neither!\n";
++       return "Well, I do like being moved around!\n";
+ }
+</screen>
+
+      <para>Your changes are all based on revision 4. They cannot be
+        committed because Harry has already checked in revision 5:</para>
+
+      <screen>
+$ svn commit -m "Small fixes"
+Sending        code/bar.c
+Sending        code/foo.c
+Transmitting file data ..
+svn: Commit failed (details follow):
+svn: File not found: transaction '5-5', path '/trunk/code/bar.c'
+</screen>
+<!-- XXX: That error message should be cleaned up! -->
+
+      <para>It is now mandatory to run <command>svn update</command>.
+        This causes a tree conflict to be flagged:</para>
+
+      <screen>
+$ svn update
+   C code/bar.c
+A    code/baz.c
+U    Makefile
+Updated to revision 5.
+Summary of conflicts:
+  Tree conflicts: 1
+</screen>
+
+      <para>During <command>svn update</command>, tree conflicts are
+        signified by a capital C in the fourth output column. Details
+        about the conflict can be seen in the output of
+        <command>svn status</command>:</para>
+
+      <screen>
+$ svn status
+M       code/foo.c
+A  +  C code/bar.c
+      >   local edit, incoming delete upon update
+M       code/baz.c
+</screen>
+
+      <para>Note how bar.c is automatically scheduled for re-addition
+        in your working copy, which simplifies things in case you want
+        to keep the file.</para>
+
+      <para>Because a move in Subversion is implemented as a copy operation
+        followed by a delete operation, and these two operations cannot
+        be easily related to one another during an update, all Subversion
+        can warn you about is an incoming delete operation on a locally
+        modified file.
+        This delete operation <emphasis>may</emphasis> be part of a move,
+        or it could be a genuine delete operation. Talking to your
+        collaborators, or, as a last resort, <command>svn log</command>,
+        is a good way to find out what has actually happened.</para>
+
+      <para>Both <filename>foo.c</filename> and <filename>baz.c</filename>
+        are reported as locally modified in the output of
+        <command>svn status</command>.  You made the changes to
+        <filename>foo.c</filename> yourself, so this should not be
+        surprising. But why is <filename>baz.c</filename> reported as
+        locally modified?</para>
+
+      <para>
+        The answer is that despite the limitations of the move  
implementation,
+        Subversion was smart enough to transfer your local edits in
+        <filename>bar.c</filename> into <filename>baz.c</filename>:</para>
+
+    <screen>
+Index: code/baz.c
+===================================================================
+--- code/baz.c  (revision 5)
++++ code/baz.c  (working copy)
+@@ -1,4 +1,4 @@
+ const char* bar(void)
+ {
+-       return "Me neither!\n";
++       return "Well, I do like being moved around!\n";
+ }
+</screen>
+
+      <warning>
+        <para>This only works if <filename>bar.c</filename> in your working
+          copy is based on the revision in which <filename>bar.c</filename>
+          was last modified before being moved in the repository.
+          Otherwise, Subversion will resort to retreiving
+          <filename>baz.c</filename> from the repository, and will not
+          try to transfer your local modifications to it. You will have
+          to do so manually.
+        </para>
+      </warning>
+
+
+      <para><filename>bar.c</filename> is now said to be the
+        <firstterm>victim</firstterm> of a tree conflict.
+        It cannot be committed until the conflict is resolved:</para>
+
+      <screen>
+$ svn commit -m "Small fixes"
+svn: Commit failed (details follow):
+svn: Aborting commit: 'code/bar.c' remains in conflict
+</screen>
+
+      <para>So how can this conflict be resolved? You can either agree
+        or disagree with the move Harry made. In case you agree, you can
+        delete <filename>bar.c</filename> and mark the tree conflict as
+        resolved:</para>
+
+      <screen>
+$ svn remove --force code/bar.c
+D         code/bar.c
+$ svn resolve --accept=working code/bar.c
+Resolved conflicted state of 'code/bar.c'
+$ svn status
+M       code/foo.c
+M       code/baz.c
+$ svn diff
+Index: code/foo.c
+===================================================================
+--- code/foo.c  (revision 5)
++++ code/foo.c  (working copy)
+@@ -3,5 +3,5 @@
+ int main(int argc, char *argv[])
+ {
+        printf("I don't like being moved around!\n%s", bar());
+-       return 0;
++       return 1;
+ }
+Index: code/baz.c
+===================================================================
+--- code/baz.c  (revision 5)
++++ code/baz.c  (working copy)
+@@ -1,4 +1,4 @@
+ const char* bar(void)
+ {
+-       return "Me neither!\n";
++       return "Well, I do like being moved around!\n";
+ }
+</screen>
+
+      <para>If you do not agree with the move, you can delete
+        <filename>baz.c</filename> instead, after making sure any
+        changes made to it after it was renamed are either preserved
+        or not worth keeping. Do not forget to revert the changes
+        Harry made to the <filename>Makefile</filename>.
+        Since <filename>bar.c</filename> is already scheduled for
+        re-addition, there is nothing else left to do, and the conflict
+        can be marked resolved:</para>
+
+     <screen>
+$ svn remove --force code/baz.c
+D         code/baz.c
+$ svn resolve --accept=working code/bar.c
+Resolved conflicted state of 'code/bar.c'
+M       code/foo.c
+A  +    code/bar.c
+D       code/baz.c
+M       Makefile
+$ svn diff
+Index: code/foo.c
+===================================================================
+--- code/foo.c	(revision 5)
++++ code/foo.c	(working copy)
+@@ -3,5 +3,5 @@
+ int main(int argc, char *argv[])
+ {
+ 	printf("I don't like being moved around!\n%s", bar());
+-	return 0;
++	return 1;
+ }
+Index: code/bar.c
+===================================================================
+--- code/bar.c	(revision 5)
++++ code/bar.c	(working copy)
+@@ -1,4 +1,4 @@
+ const char* bar(void)
+ {
+-	return "Me neither!\n";
++	return "Well, I do like being moved around!\n";
+ }
+Index: code/baz.c
+===================================================================
+--- code/baz.c	(revision 5)
++++ code/baz.c	(working copy)
+@@ -1,4 +0,0 @@
+-const char* bar(void)
+-{
+-	return "Me neither!\n";
+-}
+Index: Makefile
+===================================================================
+--- Makefile	(revision 5)
++++ Makefile	(working copy)
+@@ -1,2 +1,2 @@
+ foo:
+-	$(CC) -o $@ code/foo.c code/baz.c
++	$(CC) -o $@ code/foo.c code/bar.c
+</screen>
+
+      <para>In either case, you have now resolved your first tree
+         conflict!  You can commit your changes and tell Harry during
+         tea break about all the extra work he caused for you.</para>
+
+    </sect2>
    </sect1>

    <!-- =================================================================  
-->




More information about the svnbook-dev mailing list