diff -r dc2b8c005697 -r 4688945f316c mercurial/commands.py --- a/mercurial/commands.py Fri Oct 09 03:53:46 2015 +0900 +++ b/mercurial/commands.py Fri Oct 09 03:53:47 2015 +0900 @@ -4407,10 +4407,11 @@ 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 @@ 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.