You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bb...@apache.org on 2019/09/18 10:52:42 UTC
[mesos] 05/09: Switched commit hooks to pre-commit.
This is an automated email from the ASF dual-hosted git repository.
bbannier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 454661dd0dcbb7a7bc87ac58ad74fd6dd04c5c15
Author: Benjamin Bannier <bb...@apache.org>
AuthorDate: Wed Sep 18 11:37:14 2019 +0200
Switched commit hooks to pre-commit.
This patch switches commit hooks to be orchestrated by the pre-commit
tool mirroring the previous linters invoked through git commit
hooks (orchestrated by `support/mesos-style.py` or standalone hooks).
Using pre-commit removes the burden of maintaining
`support/mesos-style.py`, making sure that hooks have the expected
environment (e.g., Python version, Node installed). Additionally,
upstream provides a number of additional linters which are not hard to
add to Mesos' hooks.
Review: https://reviews.apache.org/r/71205/
---
docs/advanced-contribution.md | 3 +-
support/gitignore | 1 +
support/pre-commit-config.yaml | 48 ++++++++++++++++++++++++++++
support/setup-dev.bat | 18 +++++------
support/setup-dev.sh | 72 ++++++++++--------------------------------
5 files changed, 77 insertions(+), 65 deletions(-)
diff --git a/docs/advanced-contribution.md b/docs/advanced-contribution.md
index 6582849..5fbfcb9 100644
--- a/docs/advanced-contribution.md
+++ b/docs/advanced-contribution.md
@@ -15,6 +15,7 @@ If you'd like to make significant contributions to Mesos, then you'll want to be
<br/><br/>
* Required installations
+ RBtools (0.7.10 is known to work, 1.0.1 appears to have an issue)
+ + [pre-commit](https://pre-commit.com/#install)
## Issue Tracking, Code Review, and Mailing Lists
@@ -64,7 +65,7 @@ Here is the standard procedure for proposing and making changes to Mesos:
1. Create one or more test cases to exercise the bug or the feature (the Mesos team uses [test-driven development](http://en.wikipedia.org/wiki/Test-driven_development)). Before you start coding, make sure these test cases all fail.
1. The [testing patterns](testing-patterns.md) page has some suggestions for writing test cases.
2. Make your changes to the code (using whatever IDE/editor you choose) to actually fix the bug or implement the feature.
- 1. Before beginning, please read the [Mesos C++ Style Guide](c++-style-guide.md). It is recommended to use the git pre-commit hook (`support/hooks/pre-commit`) to automatically check for style errors. See the hook script for instructions to enable it.
+ 1. Before beginning, please read the [Mesos C++ Style Guide](c++-style-guide.md). It is recommended to use the git pre-commit hook to automatically check for style errors. The hooks are set up by invoking `./support/setup_dev.sh`.
2. Most of your changes will probably be to files inside of `BASE_MESOS_DIR`
3. From inside of the root Mesos directory: `./bootstrap` and `./support/setup-dev.sh`.
4. To build, we recommend that you don't build inside of the src directory. We recommend you do the following:
diff --git a/support/gitignore b/support/gitignore
index 703b14b..08280cd 100644
--- a/support/gitignore
+++ b/support/gitignore
@@ -23,6 +23,7 @@ missing
# Files created by ./support/setup-dev.sh
.clang-format
.clang-tidy
+.pre-commit-config.yaml
.reviewboardrc
.gitlint
CPPLINT.cfg
diff --git a/support/pre-commit-config.yaml b/support/pre-commit-config.yaml
new file mode 100644
index 0000000..547a4fb
--- /dev/null
+++ b/support/pre-commit-config.yaml
@@ -0,0 +1,48 @@
+default_stages: [commit]
+repos:
+- repo: local
+ hooks:
+ - id: split
+ name: Check that commits are split by project
+ entry: python ./support/mesos-split.py
+ language: python
+ language_version: 'python3'
+ stages: [commit]
+ require_serial: true
+ - id: license
+ name: Check required license headers
+ description: license
+ language: python
+ language_version: 'python3'
+ entry: python ./support/check-license.py
+ types: [text]
+ files: '.*\.(cpp|hpp|py)$' # TODO(bbannier): also check shell scripts.
+ - id: cpplint
+ name: cpplint
+ entry: python ./support/cpplint.py
+ language: python
+ language_version: 'python2'
+ types: [c++]
+ args: ['--extensions=hpp,cpp']
+- repo: https://github.com/jorisroovers/gitlint
+ rev: v0.12.0
+ hooks:
+ - id: gitlint
+ stages: [commit-msg]
+- repo: https://github.com/pre-commit/mirrors-pylint
+ rev: v2.3.1
+ hooks:
+ - id: pylint
+ args: ['--score=n', '--rcfile=support/pylint.config']
+ files: '(support).*'
+- repo: https://github.com/pre-commit/mirrors-eslint
+ rev: v6.3.0
+ hooks:
+ - id: eslint
+ args: ['-c', 'support/.eslintrc.js']
+ exclude: '^(site/source/assets/js/|src/webui/assets/libs/)'
+- repo: https://github.com/jumanjihouse/pre-commit-hooks
+ rev: 1.11.0
+ hooks:
+ - id: require-ascii
+ exclude: '^(docs/(committers.md|contributors.yaml))|(site|src/webui)/'
diff --git a/support/setup-dev.bat b/support/setup-dev.bat
index 3f4154a..df3382b 100644
--- a/support/setup-dev.bat
+++ b/support/setup-dev.bat
@@ -35,15 +35,6 @@ fsutil reparsepoint query "support" | find "Symbolic Link" >nul && (
goto not_in_root
)
-:: Install mesos default hooks and gitignore template.
-if not exist .git\hooks\pre-commit (
- mklink .git\hooks\pre-commit ..\..\support\hooks\pre-commit
-)
-
-if not exist .git\hooks\post-rewrite (
- mklink .git\hooks\post-rewrite ..\..\support\hooks\post-rewrite
-)
-
if not exist .gitignore (
mklink .gitignore support\gitignore
)
@@ -64,6 +55,15 @@ if not exist .gitlint (
mklink .gitlint support\gitlint
)
+if not exist .pre-commit-config.yaml (
+ mklink .pre-commit-config.yaml support\pre-commit-config.yaml
+)
+
+:: Install mesos default hooks and gitignore template.
+pre-commit install-hooks
+pre-commit install --hook-type pre-commit
+pre-commit install --hook-type commit-msg
+
goto:eof
diff --git a/support/setup-dev.sh b/support/setup-dev.sh
index 183effa..d171234 100755
--- a/support/setup-dev.sh
+++ b/support/setup-dev.sh
@@ -26,61 +26,6 @@ __EOF__
exit 1
fi
-# Helper functions to get the absolute path of a directory as well as compute
-# the relative path between two directories.
-# Unfortunately these functions are not as readable as, say, python's
-# os.path.relpath method, but they allow us to avoid a hard dependence on
-# python or other tools during bootstrap.
-abspath() {
- cd "`dirname "${1}"`"
- echo "${PWD}"/"`basename "${1}"`"
- cd "${OLDPWD}"
-}
-relpath() {
- local from to up
- from="`abspath "${1%/}"`" to="`abspath "${2%/}"/`"
- while test "${to}" = "${to#"${from}"/}" \
- -a "${to}" != "${from}"; do
- from="${from%/*}" up="../${up}"
- done
- to="${up%/}${to#${from}}"
- echo "${to:-.}"
-}
-
-# Grab a reference to the repo's git directory. Usually this is simply .git in
-# the repo's top level directory. However, when submodules are used, it may
-# appear elsewhere. The most up-to-date way of finding this directory is to use
-# `git rev-parse --git-common-dir`. This is necessary to support things like
-# git worktree in addition to git submodules. However, as of January 2016,
-# support for the '--git-common-dir' flag is fairly new, forcing us to fall
-# back to the older '--git-dir' flag if '--git-common-dir' is not supported. We
-# do this by checking the output of `git rev-parse --git-common-dir` and seeing
-# if it gives us a valid directory back. If not, we set the git directory using
-# the '--git-dir' flag instead.
-_gitdir=`git rev-parse --git-common-dir`
-if test ! -d "${_gitdir}"; then
- _gitdir=`git rev-parse --git-dir`
-fi
-
-# Grab a reference to the git hooks directory as well as the relative path from
-# the git hooks directory to the current directory.
-_hooksdir=${_gitdir}/hooks
-_relpath=`relpath "${_hooksdir}" "${PWD}"`
-
-# Install mesos default hooks and gitignore template.
-if test ! -e "${_hooksdir}/pre-commit"; then
- ln -s "${_relpath}/support/hooks/pre-commit" "${_hooksdir}/pre-commit"
-fi
-
-if test ! -e "${_hooksdir}/post-rewrite"; then
- ln -s "${_relpath}/support/hooks/post-rewrite" "${_hooksdir}/post-rewrite"
-fi
-
-if test ! -e "${_hooksdir}/commit-msg"; then
- ln -s "${_relpath}/support/hooks/commit-msg" "${_hooksdir}/commit-msg"
-fi
-
-
if test ! -e .gitignore; then
ln -s support/gitignore .gitignore
fi
@@ -104,3 +49,20 @@ fi
if test ! -e .gitlint; then
ln -s support/gitlint .gitlint
fi
+
+if test ! -e .pre-commit-config.yaml; then
+ ln -s support/pre-commit-config.yaml .pre-commit-config.yaml
+fi
+
+# Install Mesos default hooks and gitignore template.
+if ! command pre-commit; then
+ cat >&2 <<__EOF__
+
+Please install pre-commit to excercise Mesos linters, https://pre-commit.com/#install.
+__EOF__
+ exit 1
+fi
+
+pre-commit install-hooks
+pre-commit install --hook-type pre-commit
+pre-commit install --hook-type commit-msg