Patchwork [1,of,2] archive: raise error.Abort if the file pattern matches no files

login
register
mail settings
Submitter Angel Ezquerra
Date March 21, 2013, 10:44 p.m.
Message ID <e068221f22216fbddf7f.1363905856@Angel-PC.localdomain>
Download mbox | patch
Permalink /patch/1152/
State Superseded, archived
Commit 88d1b59f69060a1e929b7db6ac0b29fa2b194e28
Delegated to: Augie Fackler
Headers show

Comments

Angel Ezquerra - March 21, 2013, 10:44 p.m.
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1363900155 -3600
#      Thu Mar 21 22:09:15 2013 +0100
# Node ID e068221f22216fbddf7f6d54c1d27bf264defe87
# Parent  d844e3879f9b1ecac0114ae688093781d5cc3202
archive: raise error.Abort if the file pattern matches no files

Patch

diff --git a/mercurial/archival.py b/mercurial/archival.py
--- a/mercurial/archival.py
+++ b/mercurial/archival.py
@@ -13,6 +13,7 @@ 
 import cStringIO, os, tarfile, time, zipfile
 import zlib, gzip
 import struct
+import error
 
 # from unzip source code:
 _UNX_IFREG = 0x8000
@@ -286,8 +287,11 @@ 
 
     if matchfn:
         files = [f for f in ctx.manifest().keys() if matchfn(f)]
+        if not files:
+            raise error.Abort(_('no files match the archive pattern'))
     else:
         files = ctx.manifest().keys()
+
     files.sort()
     total = len(files)
     repo.ui.progress(_('archiving'), 0, unit=_('files'), total=total)
diff --git a/tests/test-archive.t b/tests/test-archive.t
--- a/tests/test-archive.t
+++ b/tests/test-archive.t
@@ -289,6 +289,16 @@ 
   *-----* (glob)
   \s*147\s+2 files (re)
 
+show an error when a provided pattern matches no files
+
+  $ hg archive -I file_that_does_not_exist.foo ../empty.zip
+  abort: no files match the archive pattern
+  [255]
+
+  $ hg archive -X * ../empty.zip
+  abort: no files match the archive pattern
+  [255]
+
   $ cd ..
 
 issue3600: check whether "hg archive" can create archive files which