D6038: push: added clear warning message when pushing a closed branch(issue6080)

taapas1128 (Taapas Agrawal) phabricator at mercurial-scm.org
Fri Mar 8 14:25:19 EST 2019


taapas1128 updated this revision to Diff 14412.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6038?vs=14401&id=14412

REVISION DETAIL
  https://phab.mercurial-scm.org/D6038

AFFECTED FILES
  mercurial/discovery.py
  tests/test-push-warn.t

CHANGE DETAILS

diff --git a/tests/test-push-warn.t b/tests/test-push-warn.t
--- a/tests/test-push-warn.t
+++ b/tests/test-push-warn.t
@@ -791,3 +791,32 @@
   [255]
 
   $ cd ..
+
+Test regarding pushing of a closed branch(Issue6080)
+
+  $ hg init x
+  $ cd x
+  $ hg -q branch a
+  $ echo 0 > foo
+  $ hg -q ci -Am 0
+  $ echo 1 > foo
+  $ hg -q ci -m 1
+  $ hg -q up 0
+  $ cd ..
+
+  $ hg -q clone x z
+  $ cd z
+
+  $ hg -q branch foo
+  $ echo 0 > foo
+  $ hg -q ci -Am 0
+  $ echo 1 > foo
+  $ hg -q ci -m 1
+  $ hg ci --close-branch -m 'closing branch foo'
+  $ hg -q up 0
+  $ hg push ../x
+  pushing to ../x
+  searching for changes
+  abort: push creates new remote branches: foo (closed)!
+  (use 'hg push --new-branch' to create new remote branches)
+  [255]
diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -344,13 +344,22 @@
     pushop.pushbranchmap = headssum
     newbranches = [branch for branch, heads in headssum.iteritems()
                    if heads[0] is None]
+    # Makes a list of closed branches
+    closedbranches = []
+    for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
+        if isclosed == True:
+            closedbranches.append((tag))
+
     # 1. Check for new branches on the remote.
     if newbranches and not newbranch:  # new branch requires --new-branch
         branchnames = ', '.join(sorted(newbranches))
-        raise error.Abort(_("push creates new remote branches: %s!")
-                           % branchnames,
-                         hint=_("use 'hg push --new-branch' to create"
-                                " new remote branches"))
+        if closedbranches and newbranches:
+            errmsg = (_("push creates new remote branches: %s (closed)!")
+                        % branchnames)
+        else:
+            errmsg = (_("push creates new remote branches: %s!")% branchnames)
+        hint=_("use 'hg push --new-branch' to create new remote branches")
+        raise error.Abort(errmsg, hint=hint)
 
     # 2. Find heads that we need not warn about
     nowarnheads = _nowarnheads(pushop)



To: taapas1128, #hg-reviewers
Cc: pulkit, mharbison72, mercurial-devel


More information about the Mercurial-devel mailing list