subrepo: add bailifchanged to centralize raising Abort if subrepo is dirty
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Wed, 25 Mar 2015 13:55:35 +0900
changeset 24471 1ff35d76421c
parent 24470 76b0b0fed2e3
child 24472 1bf71faf042e
subrepo: add bailifchanged to centralize raising Abort if subrepo is dirty This patch also centralizes composing dirty reason message like "uncommitted changes in subrepository 'xxxx'".
hgext/strip.py
mercurial/cmdutil.py
mercurial/merge.py
mercurial/subrepo.py
tests/test-mq-subrepo-svn.t
tests/test-mq-subrepo.t
tests/test-subrepo.t
--- a/hgext/strip.py	Wed Mar 25 13:55:32 2015 +0900
+++ b/hgext/strip.py	Wed Mar 25 13:55:35 2015 +0900
@@ -23,10 +23,8 @@
     else:
         bctx = wctx.parents()[0]
     for s in sorted(wctx.substate):
-        if wctx.sub(s).dirty(True):
-            raise util.Abort(
-                _("uncommitted changes in subrepository %s") % s)
-        elif s not in bctx.substate or bctx.sub(s).dirty():
+        wctx.sub(s).bailifchanged(True)
+        if s not in bctx.substate or bctx.sub(s).dirty():
             inclsubs.append(s)
     return inclsubs
 
--- a/mercurial/cmdutil.py	Wed Mar 25 13:55:32 2015 +0900
+++ b/mercurial/cmdutil.py	Wed Mar 25 13:55:35 2015 +0900
@@ -282,8 +282,7 @@
         raise util.Abort(_('uncommitted changes'))
     ctx = repo[None]
     for s in sorted(ctx.substate):
-        if ctx.sub(s).dirty():
-            raise util.Abort(_("uncommitted changes in subrepo %s") % s)
+        ctx.sub(s).bailifchanged()
 
 def logmessage(ui, opts):
     """ get the log message according to -m and -l option """
--- a/mercurial/merge.py	Wed Mar 25 13:55:32 2015 +0900
+++ b/mercurial/merge.py	Wed Mar 25 13:55:35 2015 +0900
@@ -1045,9 +1045,7 @@
                 raise util.Abort(_("uncommitted changes"),
                                  hint=_("use 'hg status' to list changes"))
             for s in sorted(wc.substate):
-                if wc.sub(s).dirty():
-                    raise util.Abort(_("uncommitted changes in "
-                                       "subrepository '%s'") % s)
+                wc.sub(s).bailifchanged()
 
         elif not overwrite:
             if p1 == p2: # no-op update
--- a/mercurial/subrepo.py	Wed Mar 25 13:55:32 2015 +0900
+++ b/mercurial/subrepo.py	Wed Mar 25 13:55:35 2015 +0900
@@ -402,6 +402,13 @@
             return _("uncommitted changes in subrepository '%s'"
                      ) % subrelpath(self)
 
+    def bailifchanged(self, ignoreupdate=False):
+        """raise Abort if subrepository is ``dirty()``
+        """
+        dirtyreason = self.dirtyreason(ignoreupdate=ignoreupdate)
+        if dirtyreason:
+            raise util.Abort(dirtyreason)
+
     def basestate(self):
         """current working directory base state, disregarding .hgsubstate
         state and working directory modifications"""
--- a/tests/test-mq-subrepo-svn.t	Wed Mar 25 13:55:32 2015 +0900
+++ b/tests/test-mq-subrepo-svn.t	Wed Mar 25 13:55:35 2015 +0900
@@ -50,7 +50,7 @@
   $ cd ..
   $ hg status -S        # doesn't show status for svn subrepos (yet)
   $ hg qnew -m1 1.diff
-  abort: uncommitted changes in subrepository sub
+  abort: uncommitted changes in subrepository 'sub'
   [255]
 
   $ cd ..
--- a/tests/test-mq-subrepo.t	Wed Mar 25 13:55:32 2015 +0900
+++ b/tests/test-mq-subrepo.t	Wed Mar 25 13:55:35 2015 +0900
@@ -102,7 +102,7 @@
   A .hgsub
   A sub/a
   % qnew -X path:no-effect -m0 0.diff
-  abort: uncommitted changes in subrepository sub
+  abort: uncommitted changes in subrepository 'sub'
   [255]
   % update substate when adding .hgsub w/clean updated subrepo
   A .hgsub
@@ -117,7 +117,7 @@
   M .hgsub
   A sub2/a
   % qnew --cwd .. -R repo-2499-qnew -X path:no-effect -m1 1.diff
-  abort: uncommitted changes in subrepository sub2
+  abort: uncommitted changes in subrepository 'sub2'
   [255]
   % update substate when modifying .hgsub w/clean updated subrepo
   M .hgsub
@@ -161,7 +161,7 @@
   A .hgsub
   A sub/a
   % qrefresh
-  abort: uncommitted changes in subrepository sub
+  abort: uncommitted changes in subrepository 'sub'
   [255]
   % update substate when adding .hgsub w/clean updated subrepo
   A .hgsub
@@ -177,7 +177,7 @@
   M .hgsub
   A sub2/a
   % qrefresh
-  abort: uncommitted changes in subrepository sub2
+  abort: uncommitted changes in subrepository 'sub2'
   [255]
   % update substate when modifying .hgsub w/clean updated subrepo
   M .hgsub
@@ -300,7 +300,7 @@
   record this change to '.hgsub'? [Ynesfdaq?] y
   
   warning: subrepo spec file .hgsub not found
-  abort: uncommitted changes in subrepository sub
+  abort: uncommitted changes in subrepository 'sub'
   [255]
   % update substate when adding .hgsub w/clean updated subrepo
   A .hgsub
@@ -335,7 +335,7 @@
   +sub2 = sub2
   record this change to '.hgsub'? [Ynesfdaq?] y
   
-  abort: uncommitted changes in subrepository sub2
+  abort: uncommitted changes in subrepository 'sub2'
   [255]
   % update substate when modifying .hgsub w/clean updated subrepo
   M .hgsub
--- a/tests/test-subrepo.t	Wed Mar 25 13:55:32 2015 +0900
+++ b/tests/test-subrepo.t	Wed Mar 25 13:55:35 2015 +0900
@@ -96,7 +96,7 @@
 
   $ echo b >> s/a
   $ hg backout tip
-  abort: uncommitted changes in subrepo s
+  abort: uncommitted changes in subrepository 's'
   [255]
   $ hg revert -C -R s s/a