hghooks: filter closed branch heads (bug 1100027)
authorGregory Szorc <gps@mozilla.com>
Sat, 15 Nov 2014 14:31:32 -0800
changeset 1525 b3d096e1c9d143927a44069a77971e348a440350
parent 1524 ad4baaa3ecb7f34db2a79ddbe5fce06cf137bd42
child 1526 48137ffb7d003ac5c8ad84058947f5b455e96c0f
push id351
push usergszorc@mozilla.com
push dateSat, 15 Nov 2014 22:31:37 +0000
treeherderversion-control-tools@b3d096e1c9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1100027
hghooks: filter closed branch heads (bug 1100027) The switch of APIs in f289c95070f1 for Mercurial 3.x API compatibility inadvertently brought closed branch heads into the mix. We now filter closed branch heads in the hook. A test has been added. The test broke before the corresponding change in the hook.
hghooks/mozhghooks/single_head_per_branch.py
hghooks/tests/test-single_head_per_branch.t
--- a/hghooks/mozhghooks/single_head_per_branch.py
+++ b/hghooks/mozhghooks/single_head_per_branch.py
@@ -13,15 +13,18 @@
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 def hook(ui, repo, **kwargs):
     for branch, heads in repo.branchmap().iteritems():
+        # Filter closed branch heads.
+        heads = [h for h in heads if not repo[h].closesbranch()]
+
         if len(heads) > 1:
             print "\n\n************************** ERROR ****************************"
             print "Multiple heads detected on branch '%s'" % branch
             print "Only one head per branch is allowed!"
             print "*************************************************************\n\n"
             return 1
     return 0
--- a/hghooks/tests/test-single_head_per_branch.t
+++ b/hghooks/tests/test-single_head_per_branch.t
@@ -63,16 +63,40 @@ Merging the two heads and pushing is all
   searching for changes
   adding changesets
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 1 files
 
   $ cd ..
 
+A closed branch head shouldn't impact things
+
+  $ cd mozilla-central
+  $ hg -q up -r tip^
+  $ echo 'will close' > file.txt
+  $ hg commit -m 'creating new head on default'
+  created new head
+  $ hg commit --close-branch -m 'closing old default branch'
+
+  $ cd ../client
+  $ hg -q pull ../mozilla-central
+
+  $ echo 'after closed branch' > file.txt
+  $ hg commit -m 'after closed branch'
+  $ hg push ../mozilla-central
+  pushing to ../mozilla-central
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+
+  $ cd ..
+
 A repository with multiple branches can still push when this hook is active
 
   $ hg -q clone mozilla-central client2
   $ cd client2
   $ hg branch newbranch
   marked working directory as branch newbranch
   (branches are permanent and global, did you want a bookmark?)
   $ echo 'newcontent' > file.txt