Clean up logic and messages for overwrite
authorChristian Ebert <blacktrash@gmx.net>
Thu, 19 Jul 2007 16:16:09 +0200
changeset 203 20eaa6147391
parent 202 e2a2f9ca8271
child 204 2d089b691b31
Clean up logic and messages for overwrite Obtain both findcmd, bail_if_changed via try error block. Change test output accordingly.
hgkw/keyword.py
tests/test-keyword.out
--- a/hgkw/keyword.py	Thu Jul 19 04:07:20 2007 +0200
+++ b/hgkw/keyword.py	Thu Jul 19 16:16:09 2007 +0200
@@ -82,13 +82,15 @@
 from mercurial import commands, cmdutil, context, fancyopts
 from mercurial import filelog, localrepo, templater, util, hg
 from mercurial.i18n import gettext as _
-# findcmd might be in cmdutil or commands
-# depending on mercurial version
-if hasattr(cmdutil, 'findcmd'):
+import os, re, shutil, sys, tempfile, time
+
+# findcmd, bail_if_changed were in commands until 0c61124ad877
+try:
     findcmd = cmdutil.findcmd
-else:
+    bail_if_changed = cmdutil.bail_if_changed
+except AttributeError:
     findcmd = commands.findcmd
-import os, re, shutil, sys, tempfile, time
+    bail_if_changed = commands.bail_if_changed
 
 commands.optionalrepo += ' kwdemo'
 
@@ -265,12 +267,10 @@
     '''Expands/shrinks keywords in working directory.'''
     wlock = repo.wlock()
     try:
+        bail_if_changed(repo)
         ctx = repo.changectx()
         if not ctx:
-            raise hg.RepoError(_('no changeset found'))
-        for changed in repo.status()[:4]:
-            if changed:
-                raise util.Abort(_('local changes detected'))
+            raise hg.RepoError(_('no revision checked out'))
         kwfmatcher = keywordmatcher(ui, repo)
         if kwfmatcher is None:
             ui.warn(_('no files configured for keyword expansion\n'))
@@ -282,8 +282,7 @@
             files = m.keys()
         files = [f for f in files if kwfmatcher(f) and not os.path.islink(f)]
         if not files:
-            ui.warn(_('given files not tracked or '
-                      'not configured for expansion\n'))
+            ui.warn(_('files not configured for expansion or untracked\n'))
             return
         kwt = kwtemplater(ui, repo, node=ctx.node(), expand=expand)
         kwt.overwrite(files, m, commit=False)
--- a/tests/test-keyword.out	Thu Jul 19 04:07:20 2007 +0200
+++ b/tests/test-keyword.out	Thu Jul 19 16:16:09 2007 +0200
@@ -32,6 +32,7 @@
         keyword. In that case run "hg kwshrink", reimport, and then
         "hg kwexpand".
         Or, better, use bundle/unbundle to share changes.
+list of commands (use "hg help -v keyword" to show aliases and global options):
  kwdemo     print [keywordmaps] configuration and an expansion example
  kwexpand   expand keywords in working directory
  kwshrink   revert expanded keywords in working directory
@@ -54,7 +55,7 @@
 $Id: demo.txt,v xxxxxxxxxxxx 2000/00/00 00:00:00 test $
 $Revision: xxxxxxxxxxxx $
 % kwshrink should abort in empty/invalid repo
-abort: no changeset found!
+abort: no revision checked out!
 % cat
 expand $Id$
 ignore $Id$