# HG changeset patch # User Christian Ebert # Date 1184854569 -7200 # Node ID 20eaa614739104e0fc828928ff0f4bbcc1a04396 # Parent e2a2f9ca8271d0dc678bf04f2f1580e81902a6fc Clean up logic and messages for overwrite Obtain both findcmd, bail_if_changed via try error block. Change test output accordingly. diff -r e2a2f9ca8271 -r 20eaa6147391 hgkw/keyword.py --- 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) diff -r e2a2f9ca8271 -r 20eaa6147391 tests/test-keyword.out --- 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$