hgkw/keyword.py
changeset 203 20eaa6147391
parent 201 e826c3cdc52d
child 204 2d089b691b31
--- 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)