Patchwork D6038: push: added clear warning message when pushing closed branches(issue6080)

login
register
mail settings
Submitter phabricator
Date April 25, 2019, 6:08 p.m.
Message ID <809c7398c659a8b8376bbd3656c7fcb5@localhost.localdomain>
Download mbox | patch
Permalink /patch/39831/
State Not Applicable
Headers show

Comments

phabricator - April 25, 2019, 6:08 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG5997eabc7b85: push: added clear warning message when pushing closed branches(issue6080) (authored by taapas1128, committed by ).

REPOSITORY
  rHG Mercurial

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

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

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

CHANGE DETAILS




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

Patch

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,57 @@ 
   [255]
 
   $ cd ..
+
+Test regarding pushing of closed branch/branches(Issue6080)
+
+  $ hg init x
+  $ cd x
+  $ hg -q branch a
+  $ echo 0 > foo
+  $ hg -q ci -Am 0
+  $ hg -q up 0
+  $ cd ..
+
+  $ hg -q clone x z
+  $ cd z
+
+When there is a single closed branch
+
+  $ hg -q branch foo
+  $ echo 0 > foo
+  $ hg -q ci -Am 0
+  $ 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 (1 closed)!
+  (use 'hg push --new-branch' to create new remote branches)
+  [255]
+
+When there is more than one closed branches
+  $ hg -q branch bar
+  $ echo 0 > bar
+  $ hg -q ci -Am 0
+  $ hg ci --close-branch -m 'closing branch bar'
+  $ hg -q up 0
+  $ hg push ../x
+  pushing to ../x
+  searching for changes
+  abort: push creates new remote branches: bar, foo (2 closed)!
+  (use 'hg push --new-branch' to create new remote branches)
+  [255]
+
+When there are more than one new branches and not all are closed
+  $ hg -q branch bar1
+  $ echo 0 > bar1
+  $ hg -q ci -Am 0
+  $ hg -q up 0
+  $ hg push ../x
+  pushing to ../x
+  searching for changes
+  abort: push creates new remote branches: bar, bar1, foo (2 closed)!
+  (use 'hg push --new-branch' to create new remote branches)
+  [255]
+
+  $ cd ..
diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -340,13 +340,22 @@ 
     pushop.pushbranchmap = headssum
     newbranches = [branch for branch, heads in headssum.iteritems()
                    if heads[0] is None]
+    # Makes a set of closed branches
+    closedbranches = set()
+    for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
+        if isclosed:
+            closedbranches.add(tag)
+    closedbranches = (closedbranches & set(newbranches))
     # 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:
+            errmsg = (_("push creates new remote branches: %s (%d closed)!")
+                        % (branchnames, len(closedbranches)))
+        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)