[PATCH] push: do not require --force to push bookmarked head (issue2372)

Prasoon Shukla prasoon92.iitr at gmail.com
Thu Dec 19 07:01:45 CST 2013


# HG changeset patch
# User Prasoon Shukla <prasoon92.iitr at gmail.com>
# Date 1387389770 -19800
#      Wed Dec 18 23:32:50 2013 +0530
# Node ID 241543f591d7f40bb5777ce64174b420ae8e713a
# Parent  5ff0fd02385082433221d0c78a99d310257d27b3
push: do not require --force to push bookmarked head (issue2372)

When pushing, an error is raised if a new head is created at remote.
This is to avoid ambiguity for developers pulling from the remote. But,
if this head is bookmarked, then pushing shouldn't require --force.
This patch implements this function.

diff -r 5ff0fd023850 -r 241543f591d7 hgext/largefiles/reposetup.py
--- a/hgext/largefiles/reposetup.py	Mon Dec 16 12:59:32 2013 -0600
+++ b/hgext/largefiles/reposetup.py	Wed Dec 18 23:32:50 2013 +0530
@@ -406,7 +406,8 @@
             finally:
                 wlock.release()
 
-        def push(self, remote, force=False, revs=None, newbranch=False):
+        def push(self, remote, force=False, revs=None, newbranch=False,
+                 bkmark=False):
             if remote.local():
                 missing = set(self.requirements) - remote.local().supported
                 if missing:
diff -r 5ff0fd023850 -r 241543f591d7 mercurial/commands.py
--- a/mercurial/commands.py	Mon Dec 16 12:59:32 2013 -0600
+++ b/mercurial/commands.py	Wed Dec 18 23:32:50 2013 +0530
@@ -4705,10 +4705,10 @@
     finally:
         del repo._subtoppath
     result = repo.push(other, opts.get('force'), revs=revs,
-                       newbranch=opts.get('new_branch'))
+                       newbranch=opts.get('new_branch'),
+                       bkmark=bool(opts.get('bookmark')))
 
     result = not result
-
     if opts.get('bookmark'):
         bresult = bookmarks.pushtoremote(ui, repo, other, opts['bookmark'])
         if bresult == 2:
diff -r 5ff0fd023850 -r 241543f591d7 mercurial/discovery.py
--- a/mercurial/discovery.py	Mon Dec 16 12:59:32 2013 -0600
+++ b/mercurial/discovery.py	Wed Dec 18 23:32:50 2013 +0530
@@ -219,7 +219,8 @@
     unsynced = inc and set([None]) or set()
     return {None: (oldheads, newheads, unsynced)}
 
-def checkheads(repo, remote, outgoing, remoteheads, newbranch=False, inc=False):
+def checkheads(repo, remote, outgoing, remoteheads, newbranch=False, inc=False,
+               bkmark=False):
     """Check that a push won't add any outgoing head
 
     raise Abort error and display ui message as needed.
@@ -321,7 +322,10 @@
         elif len(newhs) > len(oldhs):
             # strip updates to existing remote heads from the new heads list
             dhs = sorted(newhs - bookmarkedheads - oldhs)
-        if dhs:
+        # if new head is bookmarked, we don't raise an exception
+        if dhs and bkmark and dhs[0] in repo._bookmarks.values():
+            pass
+        elif dhs:
             if error is None:
                 if branch not in ('default', None):
                     error = _("push creates new remote head %s "
diff -r 5ff0fd023850 -r 241543f591d7 mercurial/localrepo.py
--- a/mercurial/localrepo.py	Mon Dec 16 12:59:32 2013 -0600
+++ b/mercurial/localrepo.py	Wed Dec 18 23:32:50 2013 +0530
@@ -1766,7 +1766,8 @@
         """
         pass
 
-    def push(self, remote, force=False, revs=None, newbranch=False):
+    def push(self, remote, force=False, revs=None, newbranch=False,
+             bkmark=False):
         '''Push outgoing changesets (limited by revs) from the current
         repository to remote. Return an integer:
           - None means nothing to push
@@ -1866,7 +1867,7 @@
                                                         ctx))
                         discovery.checkheads(unfi, remote, outgoing,
                                              remoteheads, newbranch,
-                                             bool(inc))
+                                             bool(inc), bkmark)
 
                     # TODO: get bundlecaps from remote
                     bundlecaps = None
diff -r 5ff0fd023850 -r 241543f591d7 tests/test-bookmarks-pushpull.t
--- a/tests/test-bookmarks-pushpull.t	Mon Dec 16 12:59:32 2013 -0600
+++ b/tests/test-bookmarks-pushpull.t	Wed Dec 18 23:32:50 2013 +0530
@@ -424,4 +424,18 @@
   remote: added 1 changesets with 1 changes to 1 files
   exporting bookmark add-foo
 
+When a bookmark is pushed, don't raise an exception if a new head is created
+  $ hg bookmark changefoo
+  $ echo 'foo foo' > foo
+  $ hg ci -m 'change foo'
+  created new head
+  $ hg push -B changefoo
+  pushing to http://localhost:$HGPORT/
+  searching for changes
+  remote: adding changesets
+  remote: adding manifests
+  remote: adding file changes
+  remote: added 1 changesets with 1 changes to 1 files
+  exporting bookmark changefoo
+
   $ cd ..


More information about the Mercurial-devel mailing list