subrepo: fix merging of already merged subrepos (issue1986) stable
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Fri, 15 Jan 2010 21:08:04 +0100
branchstable
changeset 10251 a19d2993385d
parent 10249 8ebb34b0f6f7
child 10252 0bc93fa2cf2b
child 10253 b190a8125b43
subrepo: fix merging of already merged subrepos (issue1986) This fixes a bug seen when merging a main repo which contains a subrepo when both repos have been merged before. Each repo (main and sub) has two branches, both of which have been merged before. In a subrepo, if the revision to merge to is an ancestor of the current rev, then the merge should be a noop. Test provided by Steve Losh.
mercurial/subrepo.py
tests/test-subrepo
tests/test-subrepo.out
--- a/mercurial/subrepo.py	Fri Jan 15 09:50:52 2010 +0100
+++ b/mercurial/subrepo.py	Fri Jan 15 21:08:04 2010 +0100
@@ -209,9 +209,12 @@
         self._get(state)
         cur = self._repo['.']
         dst = self._repo[state[1]]
-        if dst.ancestor(cur) == cur:
+        anc = dst.ancestor(cur)
+        if anc == cur:
             self._repo.ui.debug("updating subrepo %s\n" % self._path)
             hg.update(self._repo, state[1])
+        elif anc == dst:
+            self._repo.ui.debug("skipping subrepo %s\n" % self._path)
         else:
             self._repo.ui.debug("merging subrepo %s\n" % self._path)
             hg.merge(self._repo, state[1], remind=False)
--- a/tests/test-subrepo	Fri Jan 15 09:50:52 2010 +0100
+++ b/tests/test-subrepo	Fri Jan 15 21:08:04 2010 +0100
@@ -104,3 +104,57 @@
 hg pull | sed 's/ .*sub/ ...sub/g'
 hg up # should pull t
 cat t/t
+
+echo % issue 1986
+cd ..
+rm -rf sub
+hg init main
+cd main
+
+hg init s           # subrepo layout
+cd s                #
+echo a > a          #   o   5 br
+hg ci -Am1          #  /|
+hg branch br        # o |   4 default
+echo a >> a         # | |
+hg ci -m1           # | o   3 br
+hg up default       # |/|
+echo b > b          # o |   2 default
+hg ci -Am1          # | |
+hg up br            # | o   1 br
+hg merge tip        # |/
+hg ci -m1           # o     0 default
+hg up 2
+echo c > c
+hg ci -Am1
+hg up 3
+hg merge 4
+hg ci -m1
+
+cd ..                         # main repo layout:
+echo 's = s' > .hgsub         #
+hg -R s up 2                  #   * <-- try to merge default into br again
+hg ci -Am1                    # .`|
+hg branch br                  # . o   5 br      --> substate = 5
+echo b > b                    # . |
+hg -R s up 3                  # o |   4 default --> substate = 4
+hg ci -Am1                    # | |
+hg up default                 # | o   3 br      --> substate = 2
+echo c > c                    # |/|
+hg ci -Am1                    # o |   2 default --> substate = 2
+hg up 1                       # | |     
+hg merge 2                    # | o   1 br      --> substate = 3
+hg ci -m1                     # |/    
+hg up 2                       # o     0 default --> substate = 2
+hg -R s up 4
+echo d > d
+hg ci -Am1
+hg up 3
+hg -R s up 5
+echo e > e
+hg ci -Am1
+
+hg up 5
+hg merge 4    # try to merge default into br again
+
+exit 0
--- a/tests/test-subrepo.out	Fri Jan 15 09:50:52 2010 +0100
+++ b/tests/test-subrepo.out	Fri Jan 15 21:08:04 2010 +0100
@@ -201,3 +201,43 @@
 added 1 changesets with 1 changes to 1 files
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 blah
+% issue 1986
+adding a
+marked working directory as branch br
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+adding b
+created new head
+1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+(branch merge, don't forget to commit)
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+adding c
+created new head
+1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+(branch merge, don't forget to commit)
+1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+adding .hgsub
+committing subrepository s
+marked working directory as branch br
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+adding b
+committing subrepository s
+1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+adding c
+created new head
+2 files updated, 0 files merged, 1 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+(branch merge, don't forget to commit)
+1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+adding d
+committing subrepository s
+created new head
+2 files updated, 0 files merged, 1 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+adding e
+committing subrepository s
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+(branch merge, don't forget to commit)