diff --git a/mercurial/commands.py b/mercurial/commands.py index 6470f476d6..fc64c13aa4 100644 --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1092,7 +1092,11 @@ def grep(ui, repo, pattern, *pats, **opts): reflags = 0 if opts['ignore_case']: reflags |= re.I - regexp = re.compile(pattern, reflags) + try: + regexp = re.compile(pattern, reflags) + except Exception, inst: + ui.warn(_("grep: invalid match pattern: %s!\n") % inst) + return None sep, eol = ':', '\n' if opts['print0']: sep = eol = '\0' diff --git a/tests/test-grep b/tests/test-grep index 92c00fcbe2..5ac3bda274 100755 --- a/tests/test-grep +++ b/tests/test-grep @@ -17,6 +17,8 @@ hg commit -m 3 -u eggs -d '3 0' head -n 3 port > port1 mv port1 port hg commit -m 4 -u spam -d '4 0' +echo % pattern error +hg grep '**test**' echo % simple hg grep port port echo % all diff --git a/tests/test-grep.out b/tests/test-grep.out index dd5f5b2c5e..c8ae48b7c3 100644 --- a/tests/test-grep.out +++ b/tests/test-grep.out @@ -1,3 +1,5 @@ +% pattern error +grep: invalid match pattern: nothing to repeat! % simple port:4:export port:4:vaportight