diff hgext/mq.py @ 11699:da0b9109186d

mq: support "qimport --existing --name renametothis thatexistingpatch" Before this change, the command would abort with a not too clear "patch renametothis does not exist" error. This change makes: qimport --existing --name renametothis thatexistingpatch equivalent to: qimport --existing thatexistingpatch; qrename thatexistingpatch renametothis
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Wed, 21 Jul 2010 11:53:09 +0900
parents c4f6f0a1bd5a
children 52c863295754
line wrap: on
line diff
--- a/hgext/mq.py	Sat Jul 24 00:28:20 2010 +0900
+++ b/hgext/mq.py	Wed Jul 21 11:53:09 2010 +0900
@@ -1687,11 +1687,22 @@
             if existing:
                 if filename == '-':
                     raise util.Abort(_('-e is incompatible with import from -'))
-                if not patchname:
-                    patchname = normname(filename)
-                self.check_reserved_name(patchname)
-                if not os.path.isfile(self.join(patchname)):
-                    raise util.Abort(_("patch %s does not exist") % patchname)
+                filename = normname(filename)
+                self.check_reserved_name(filename)
+                originpath = self.join(filename)
+                if not os.path.isfile(originpath):
+                    raise util.Abort(_("patch %s does not exist") % filename)
+
+                if patchname:
+                    self.check_reserved_name(patchname)
+                    checkfile(patchname)
+
+                    self.ui.write(_('renaming %s to %s\n')
+                                        % (filename, patchname))
+                    os.rename(originpath, self.join(patchname))
+                else:
+                    patchname = filename
+
             else:
                 try:
                     if filename == '-':