diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -4407,10 +4407,11 @@ def import_(ui, repo, patch1=None, *patc try: try: wlock = repo.wlock() - dsguard = cmdutil.dirstateguard(repo, 'import') if not opts.get('no_commit'): lock = repo.lock() tr = repo.transaction('import') + else: + dsguard = cmdutil.dirstateguard(repo, 'import') parents = repo.parents() for patchurl in patches: if patchurl == '-': @@ -4448,7 +4449,8 @@ def import_(ui, repo, patch1=None, *patc tr.close() if msgs: repo.savecommitmessage('\n* * *\n'.join(msgs)) - dsguard.close() + if dsguard: + dsguard.close() return ret finally: # TODO: get rid of this meaningless try/finally enclosing.