[PATCH] qpush asserts that patches do not affect unknown files

Chad Skeeters goobsoft at yahoo.com
Fri Sep 21 16:52:41 CDT 2007


# HG changeset patch
# User Chad Skeeters <goobsoft at yahoo.com>
# Date 1190410545 18000
# Node ID 687f12c0e596375f228f59cc486a6c783b936b74
# Parent  ba3dc78839686ccb285f4227a80356f7b13e6f8f
qpush asserts that patches do not affect unknown files

diff -r ba3dc7883968 -r 687f12c0e596 hgext/mq.py
--- a/hgext/mq.py	Sat Sep 15 16:07:05 2007 +0200
+++ b/hgext/mq.py	Fri Sep 21 16:35:45 2007 -0500
@@ -599,6 +599,20 @@ class queue:
                 else:
                     raise util.Abort(_("local changes found"))
         return m, a, r, d
+
+    def check_unknown(self, repo, patchname, patchdir=None):
+        if not patchdir:
+            patchdir = self.path
+
+        patchpath = os.path.join(patchdir, patchname)
+
+        affected_files = get_affected_files(patchpath)
+        modified, added, removed, deleted, unknown, ignored, clean = repo.status(None, None, files);
+        if unknown != None:
+            for f in unknown:
+                if f in affected_files:
+                    if os.path.exists(matcher.group(1)):
+                        raise util.Abort(_('Patch %s can not be applied on unknown file %s') % (patchname, f))
 
     def new(self, repo, patch, *pats, **opts):
         msg = opts.get('msg')
@@ -781,6 +795,11 @@ class queue:
             else:
                 end = self.series.index(patch, start) + 1
             s = self.series[start:end]
+
+            if not force:
+                for patchname in s:
+                    self.check_unknown(repo, patchname);
+
             all_files = {}
             try:
                 if mergeq:
@@ -2130,6 +2149,16 @@ def reposetup(ui, repo):
     if repo.local():
         repo.__class__ = mqrepo
         repo.mq = queue(ui, repo.join(""))
+
+def get_affected_files(patch_file_path):
+    files = []
+    file_path_pattern = re.compile("^\\+\\+\\+\\s[^\\\\/]*[\\\\/]([^\\t]*)\\t.*$")
+    for line in file(patch_file_path):
+        matcher = file_path_pattern.match(line);
+        if matcher != None:
+            files.append(matcher.group(1))
+    return files
+
 
 seriesopts = [('s', 'summary', None, _('print first line of patch header'))]
 
diff -r ba3dc7883968 -r 687f12c0e596 tests/test-mq.out
--- a/tests/test-mq.out	Sat Sep 15 16:07:05 2007 +0200
+++ b/tests/test-mq.out	Fri Sep 21 16:35:45 2007 -0500
@@ -260,19 +260,10 @@ M a
 M a
 % qpush failure
 Patch queue now empty
-applying foo
-applying bar
-file foo already exists
-1 out of 1 hunk FAILED -- saving rejects to file foo.rej
-patch failed, unable to continue (try -v)
-patch failed, rejects left in working dir
-Errors during apply, please fix and refresh bar
+abort: Patch bar can not be applied on unknown file foo
 ? foo
-? foo.rej
 % mq tags
-0 qparent
-1 qbase foo
-2 qtip bar tip
+abort: unknown revision 'qparent'!
 new file
 
 diff --git a/new b/new


More information about the Mercurial-devel mailing list