[PATCH] check-commit: prevent adding symlinks
Yuya Nishihara
yuya at tcha.org
Sat Apr 9 03:33:16 UTC 2016
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1460171180 -32400
# Sat Apr 09 12:06:20 2016 +0900
# Node ID e1757909c63e92b1787f7ea50e89b2deb6d96ecf
# Parent c5565fc8848dd084d104ca40c33d1acdfcff8bc6
check-commit: prevent adding symlinks
IMHO, including symlinks in source code is a sign of bad design. Also, it
doesn't work on Windows.
This patch makes check-commit use a git patch to capture "new file mode" line.
diff --git a/contrib/check-commit b/contrib/check-commit
--- a/contrib/check-commit
+++ b/contrib/check-commit
@@ -38,6 +38,7 @@ errors = [
(r"\n\+\n( |\+)\n", "adds double empty line"),
(r"\n \n\+\n", "adds double empty line"),
(r"\n\+[ \t]+def [a-z]+_[a-z]", "adds a function with foo_bar naming"),
+ (r"(?m)^new file mode 120000$", "don't add a symlink"),
]
word = re.compile('\S')
@@ -80,7 +81,7 @@ def checkcommit(commit, node=None):
return exitcode
def readcommit(node):
- return os.popen("hg export %s" % node).read()
+ return os.popen("hg export --git %s" % node).read()
if __name__ == "__main__":
exitcode = 0
diff --git a/tests/test-check-commit.t b/tests/test-check-commit.t
--- a/tests/test-check-commit.t
+++ b/tests/test-check-commit.t
@@ -12,7 +12,7 @@ Go back in the hg repo
$ cd $TESTDIR/..
$ for node in `hg log --rev 'not public() and ::.' --template '{node|short}\n'`; do
- > hg export $node | contrib/check-commit > ${TESTTMP}/check-commit.out
+ > hg export --git $node | contrib/check-commit > ${TESTTMP}/check-commit.out
> if [ $? -ne 0 ]; then
> echo "Revision $node does not comply with rules"
> echo '------------------------------------------------------'
diff --git a/tests/test-contrib-check-commit.t b/tests/test-contrib-check-commit.t
--- a/tests/test-contrib-check-commit.t
+++ b/tests/test-contrib-check-commit.t
@@ -113,3 +113,27 @@ A patch with other errors:
23: adds double empty line
+
[1]
+
+A patch with new symlink:
+
+ $ cat > patch-with-new-symlink.diff <<'EOF'
+ > # HG changeset patch
+ > # User timeless <timeless at mozdev.org>
+ > # Date 1459974801 0
+ > # Wed Apr 06 20:33:21 2016 +0000
+ > # Node ID 1fb74d8a9fec7d66a4b47b7b276584b0fc25a27a
+ > # Parent 68a946e8318894bd95d0a5b3726006bb61fda6ad
+ > pycompat: switch to util.stringio for py3 compat
+ >
+ > diff --git a/mercurial/pure/pycompat.py b/mercurial/pure/pycompat.py
+ > new file mode 120000
+ > --- /dev/null
+ > +++ b/mercurial/pure/pycompat.py
+ > @@ -0,0 +1,1 @@
+ > +../pycompat.py
+ > \ No newline at end of file
+ > EOF
+ $ cat patch-with-new-symlink.diff | $TESTDIR/../contrib/check-commit
+ 9: don't add a symlink
+ new file mode 120000
+ [1]
More information about the Mercurial-devel
mailing list