[PATCH] qpush asserts that patches do not affect unknown files
Chad Skeeters
goobsoft at yahoo.com
Mon Sep 24 17:09:01 CDT 2007
# HG changeset patch
# User Chad Skeeters <goobsoft at yahoo.com>
# Date 1190671032 18000
# Node ID 81877a068aa08b041d40d69b8c33fb324907346c
# Parent 8d00788ca5785e8144e20b7996f0ee3b374f6d45
qpush asserts that patches do not affect unknown files
diff -r 8d00788ca578 -r 81877a068aa0 hgext/mq.py
--- a/hgext/mq.py Mon Sep 24 12:42:25 2007 -0500
+++ b/hgext/mq.py Mon Sep 24 16:57:12 2007 -0500
@@ -599,6 +599,21 @@ 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)
+ for f in affected_files:
+ if os.path.exists(f):
+ modified, added, removed, deleted, unknown, ignored, clean = repo.status(None, None, [f]);
+ if unknown != None:
+ if f in unknown:
+ 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 +796,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 +2150,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 8d00788ca578 -r 81877a068aa0 tests/test-mq.out
--- a/tests/test-mq.out Mon Sep 24 12:42:25 2007 -0500
+++ b/tests/test-mq.out Mon Sep 24 16:57:12 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