[PATCH 1 of 2] commit: ignore subrepos completely if the '.hgsub' is excluded via -X

Jason Harris jason.f.harris at gmail.com
Thu Jan 26 05:31:34 CST 2012


# HG changeset patch
# User Jason Harris <jason at jasonfharris.com>
# Date 1327576926 -3600
# Branch stable
# Node ID 410354c0ee27ac8afd192f138aa9c205d1d17898
# Parent  c2e6c5ef45555ff98dd12bef335c40a91eccc390
commit: ignore subrepos completely if the '.hgsub' is excluded via -X

As a way for users to make sure that their sub repository state is not
committed, make it so that -X .hgsub actually obeys the exclusion.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1190,6 +1190,11 @@
         # Let --subrepos on the command line overide config setting.
         ui.setconfig('ui', 'commitsubrepos', True)
 
+    # if -X .hgsub is specified then ignore subrepos completely
+    excluded = opts.get('exclude')
+    if excluded and ('.hgsub' in excluded):
+            ui.setconfig('ui', 'excludesubrepos', True)
+
     extra = {}
     if opts.get('close_branch'):
         if repo['.'].node() not in repo.branchheads():
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1097,35 +1097,37 @@
             # check subrepos
             subs = []
             removedsubs = set()
-            if '.hgsub' in wctx:
-                # only manage subrepos and .hgsubstate if .hgsub is present
-                for p in wctx.parents():
-                    removedsubs.update(s for s in p.substate if match(s))
-                for s in wctx.substate:
-                    removedsubs.discard(s)
-                    if match(s) and wctx.sub(s).dirty():
-                        subs.append(s)
-                if (subs or removedsubs):
-                    if (not match('.hgsub') and
-                        '.hgsub' in (wctx.modified() + wctx.added())):
-                        raise util.Abort(
-                            _("can't commit subrepos without .hgsub"))
-                    if '.hgsubstate' not in changes[0]:
-                        changes[0].insert(0, '.hgsubstate')
-                        if '.hgsubstate' in changes[2]:
-                            changes[2].remove('.hgsubstate')
-            elif '.hgsub' in changes[2]:
-                # clean up .hgsubstate when .hgsub is removed
-                if ('.hgsubstate' in wctx and
-                    '.hgsubstate' not in changes[0] + changes[1] + changes[2]):
-                    changes[2].insert(0, '.hgsubstate')
+            if not self.ui.configbool('ui', 'excludesubrepos'):
+                if '.hgsub' in wctx:
+                    # only manage subrepos and .hgsubstate if .hgsub is present
+                    for p in wctx.parents():
+                        removedsubs.update(s for s in p.substate if match(s))
+                    for s in wctx.substate:
+                        removedsubs.discard(s)
+                        if match(s) and wctx.sub(s).dirty():
+                            subs.append(s)
+                    if (subs or removedsubs):
+                        if (not match('.hgsub') and
+                            '.hgsub' in (wctx.modified() + wctx.added())):
+                            raise util.Abort(
+                                _("can't commit subrepos without .hgsub"))
+                        if '.hgsubstate' not in changes[0]:
+                            changes[0].insert(0, '.hgsubstate')
+                            if '.hgsubstate' in changes[2]:
+                                changes[2].remove('.hgsubstate')
+                elif '.hgsub' in changes[2]:
+                    # clean up .hgsubstate when .hgsub is removed
+                    if ('.hgsubstate' in wctx and '.hgsubstate' not in
+                                changes[0] + changes[1] + changes[2]):
+                        changes[2].insert(0, '.hgsubstate')
 
-            if subs and not self.ui.configbool('ui', 'commitsubrepos', False):
-                changedsubs = [s for s in subs if wctx.sub(s).dirty(True)]
-                if changedsubs:
-                    raise util.Abort(_("uncommitted changes in subrepo %s")
-                                     % changedsubs[0],
-                                     hint=_("use --subrepos for recursive commit"))
+                if subs and not self.ui.configbool('ui', 'commitsubrepos',
+                                                                     False):
+                    changedsubs = [s for s in subs if wctx.sub(s).dirty(True)]
+                    if changedsubs:
+                        raise util.Abort(_("uncommitted changes in subrepo %s")
+                                 % changedsubs[0],
+                                 hint=_("use --subrepos for recursive commit"))
 
             # make sure all explicit patterns are matched
             if not force and match.files():


More information about the Mercurial-devel mailing list