pull: update to branch tip if there is only one head on the current branch
authorBenoit Allard <benoit@aeteurope.nl>
Fri, 14 Nov 2008 14:36:17 +0100
changeset 7372 e17dbf140035
parent 7371 6ad2b914acbd
child 7373 d9e9dd2b00fb
pull: update to branch tip if there is only one head on the current branch On pull, if the current named branch has only one head, update to it.
mercurial/commands.py
tests/test-pull-branch
tests/test-pull-branch.out
--- a/mercurial/commands.py	Fri Nov 14 13:48:23 2008 +0100
+++ b/mercurial/commands.py	Fri Nov 14 14:36:17 2008 +0100
@@ -2091,7 +2091,7 @@
     if modheads == 0:
         return
     if optupdate:
-        if modheads <= 1 or checkout:
+        if (modheads <= 1 or len(repo.branchheads()) == 1) or checkout:
             return hg.update(repo, checkout)
         else:
             ui.status(_("not updating, since new heads added\n"))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-pull-branch	Fri Nov 14 14:36:17 2008 +0100
@@ -0,0 +1,75 @@
+#!/bin/sh
+
+hg init t
+cd t
+echo 1 > foo
+hg ci -Am1 # 0
+hg branch branchA
+echo a1 > foo
+hg ci -ma1 # 1
+
+cd ..
+hg init tt
+cd tt
+hg pull ../t
+hg up branchA
+
+cd ../t
+echo a2 > foo
+hg ci -ma2 # 2
+echo % create branch B
+hg up 0
+hg branch branchB
+echo b1 > foo
+hg ci -mb1 # 3
+
+cd ../tt
+echo % a new branch is there
+hg pull -u ../t
+
+echo % develop both branch
+cd ../t
+hg up branchA
+echo a3 > foo
+hg ci -ma3 # 4
+hg up branchB
+echo b2 > foo
+hg ci -mb2 # 5
+
+cd ../tt
+echo % should succeed, no new heads
+hg pull -u ../t
+
+echo % add an head on other branch
+cd ../t
+hg up branchA
+echo a4 > foo
+hg ci -ma4 # 6
+hg up branchB
+echo b3.1 > foo
+hg ci -m b3.1 # 7
+hg up 5
+echo b3.2 > foo
+hg ci -m b3.2 # 8
+
+cd ../tt
+echo % should succeed only one head on our branch
+hg pull -u ../t
+
+cd ../t
+hg up -C branchA
+echo a5.1 > foo
+hg ci -ma5.1 # 9
+hg up 6
+echo a5.2 > foo
+hg ci -ma5.2 # 10
+hg up 7
+echo b4.1 > foo
+hg ci -m b4.1 # 11
+hg up -C 8
+echo b4.2 > foo
+hg ci -m b4.2 # 12
+
+cd ../tt
+echo % should fail new head in our branch
+hg pull -u ../t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-pull-branch.out	Fri Nov 14 14:36:17 2008 +0100
@@ -0,0 +1,60 @@
+adding foo
+marked working directory as branch branchA
+pulling from ../t
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 2 changesets with 2 changes to 1 files
+(run 'hg update' to get a working copy)
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% create branch B
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+marked working directory as branch branchB
+created new head
+% a new branch is there
+pulling from ../t
+searching for changes
+adding changesets
+adding manifests
+adding file changes
+added 2 changesets with 2 changes to 1 files (+1 heads)
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% develop both branch
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% should succeed, no new heads
+pulling from ../t
+searching for changes
+adding changesets
+adding manifests
+adding file changes
+added 2 changesets with 2 changes to 1 files
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% add an head on other branch
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+created new head
+% should succeed only one head on our branch
+pulling from ../t
+searching for changes
+adding changesets
+adding manifests
+adding file changes
+added 3 changesets with 3 changes to 1 files (+1 heads)
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+created new head
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% should fail new head in our branch
+pulling from ../t
+searching for changes
+adding changesets
+adding manifests
+adding file changes
+added 4 changesets with 4 changes to 1 files (+1 heads)
+not updating, since new heads added
+(run 'hg heads' to see heads, 'hg merge' to merge)