D609: check-code: forbid using bash in shebang

quark (Jun Wu) phabricator at mercurial-scm.org
Fri Sep 1 22:49:13 UTC 2017


quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Some platforms (ex. FreeBSD) do not have `bash` by default. Therefore it
  should not be used in test scripts.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D609

AFFECTED FILES
  contrib/check-code.py
  tests/test-editor-filename.t

CHANGE DETAILS

diff --git a/tests/test-editor-filename.t b/tests/test-editor-filename.t
--- a/tests/test-editor-filename.t
+++ b/tests/test-editor-filename.t
@@ -5,7 +5,7 @@
 Create an editor that writes its arguments to stdout and set it to $HGEDITOR.
 
   $ cat > editor.sh << EOF
-  > #!/bin/bash
+  > #!/bin/sh
   > echo "\$@"
   > exit 1
   > EOF
diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -119,7 +119,8 @@
     (r'\[[^\]]+==', '[ foo == bar ] is a bashism, use [ foo = bar ] instead'),
     (r'(^|\|\s*)grep (-\w\s+)*[^|]*[(|]\w',
      "use egrep for extended grep syntax"),
-    (r'/bin/', "don't use explicit paths for tools"),
+    (r'(?<!!)/bin/', "don't use explicit paths for tools"),
+    (r'#!.*/bash', "don't use bash in shebang, use sh"),
     (r'[^\n]\Z', "no trailing newline"),
     (r'export .*=', "don't export and assign at once"),
     (r'^source\b', "don't use 'source', use '.'"),
@@ -159,7 +160,7 @@
 ]
 
 testfilters = [
-    (r"( *)(#([^\n]*\S)?)", repcomment),
+    (r"( *)(#([^!][^\n]*\S)?)", repcomment),
     (r"<<(\S+)((.|\n)*?\n\1)", rephere),
 ]
 
@@ -232,7 +233,7 @@
 
 utestfilters = [
     (r"<<(\S+)((.|\n)*?\n  > \1)", rephere),
-    (r"( +)(#([^\n]*\S)?)", repcomment),
+    (r"( +)(#([^!][^\n]*\S)?)", repcomment),
 ]
 
 pypats = [



To: quark, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list