From b87414c74971082a8af73d913441a00f90037798 Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Fri, 23 Aug 2024 15:19:21 -0700 Subject: [PATCH] add back pre-commit hook (#33366) * add pre-commit * space * post * e --- scripts/post-commit | 7 ++++++ tools/op.sh | 56 +++++++++++++++++++++++++++------------------ tools/setup.sh | 1 + 3 files changed, 42 insertions(+), 22 deletions(-) create mode 100755 scripts/post-commit diff --git a/scripts/post-commit b/scripts/post-commit new file mode 100755 index 00000000000000..f9964639de4137 --- /dev/null +++ b/scripts/post-commit @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -e +if [[ -f .git/hooks/post-commit.d/post-commit ]]; then + .git/hooks/post-commit.d/post-commit +fi +tools/op.sh lint --fast +echo "" diff --git a/tools/op.sh b/tools/op.sh index 05a55cd35bdf55..4c792edefeba47 100755 --- a/tools/op.sh +++ b/tools/op.sh @@ -61,6 +61,16 @@ function op_get_openpilot_dir() { done } +function op_install_post_commit() { + op_get_openpilot_dir + if [[ ! -d $OPENPILOT_ROOT/.git/hooks/post-commit.d ]]; then + mkdir $OPENPILOT_ROOT/.git/hooks/post-commit.d + mv $OPENPILOT_ROOT/.git/hooks/post-commit $OPENPILOT_ROOT/.git/hooks/post-commit.d 2>/dev/null || true + fi + cd $OPENPILOT_ROOT/.git/hooks + ln -sf ../../scripts/post-commit post-commit +} + function op_check_openpilot_dir() { echo "Checking for openpilot directory..." if [[ -f "$OPENPILOT_ROOT/launch_openpilot.sh" ]]; then @@ -313,21 +323,22 @@ function op_default() { echo -e "${BOLD}${UNDERLINE}Usage:${NC} op [OPTIONS] " echo "" echo -e "${BOLD}${UNDERLINE}Commands [System]:${NC}" - echo -e " ${BOLD}check${NC} Check the development environment (git, os, python) to start using openpilot" - echo -e " ${BOLD}venv${NC} Activate the python virtual environment" - echo -e " ${BOLD}setup${NC} Install openpilot dependencies" - echo -e " ${BOLD}build${NC} Run the openpilot build system in the current working directory" - echo -e " ${BOLD}install${NC} Install the 'op' tool system wide" + echo -e " ${BOLD}check${NC} Check the development environment (git, os, python) to start using openpilot" + echo -e " ${BOLD}venv${NC} Activate the python virtual environment" + echo -e " ${BOLD}setup${NC} Install openpilot dependencies" + echo -e " ${BOLD}build${NC} Run the openpilot build system in the current working directory" + echo -e " ${BOLD}install${NC} Install the 'op' tool system wide" echo "" echo -e "${BOLD}${UNDERLINE}Commands [Tooling]:${NC}" - echo -e " ${BOLD}juggle${NC} Run PlotJuggler" - echo -e " ${BOLD}replay${NC} Run Replay" - echo -e " ${BOLD}cabana${NC} Run Cabana" + echo -e " ${BOLD}juggle${NC} Run PlotJuggler" + echo -e " ${BOLD}replay${NC} Run Replay" + echo -e " ${BOLD}cabana${NC} Run Cabana" echo "" echo -e "${BOLD}${UNDERLINE}Commands [Testing]:${NC}" - echo -e " ${BOLD}sim${NC} Run openpilot in a simulator" - echo -e " ${BOLD}lint${NC} Run the linter" - echo -e " ${BOLD}test${NC} Run all unit tests from pytest" + echo -e " ${BOLD}sim${NC} Run openpilot in a simulator" + echo -e " ${BOLD}lint${NC} Run the linter" + echo -e " ${BOLD}post-commit${NC} Install the linter as a post-commit hook" + echo -e " ${BOLD}test${NC} Run all unit tests from pytest" echo "" echo -e "${BOLD}${UNDERLINE}Options:${NC}" echo -e " ${BOLD}-d, --dir${NC}" @@ -361,17 +372,18 @@ function _op() { # parse Commands case $1 in - venv ) shift 1; op_venv "$@" ;; - check ) shift 1; op_check "$@" ;; - setup ) shift 1; op_setup "$@" ;; - build ) shift 1; op_build "$@" ;; - juggle ) shift 1; op_juggle "$@" ;; - cabana ) shift 1; op_cabana "$@" ;; - lint ) shift 1; op_lint "$@" ;; - test ) shift 1; op_test "$@" ;; - replay ) shift 1; op_replay "$@" ;; - sim ) shift 1; op_sim "$@" ;; - install ) shift 1; op_install "$@" ;; + venv ) shift 1; op_venv "$@" ;; + check ) shift 1; op_check "$@" ;; + setup ) shift 1; op_setup "$@" ;; + build ) shift 1; op_build "$@" ;; + juggle ) shift 1; op_juggle "$@" ;; + cabana ) shift 1; op_cabana "$@" ;; + lint ) shift 1; op_lint "$@" ;; + test ) shift 1; op_test "$@" ;; + replay ) shift 1; op_replay "$@" ;; + sim ) shift 1; op_sim "$@" ;; + install ) shift 1; op_install "$@" ;; + post-commit ) shift 1; op_install_post_commit "$@" ;; * ) op_default "$@" ;; esac } diff --git a/tools/setup.sh b/tools/setup.sh index bc8e41a401f473..e0a9a4f6a6325e 100755 --- a/tools/setup.sh +++ b/tools/setup.sh @@ -158,6 +158,7 @@ function git_clone() { function install_with_op() { cd $OPENPILOT_ROOT $OPENPILOT_ROOT/tools/op.sh install + $OPENPILOT_ROOT/tools/op.sh post-commit LOG_FILE=$(mktemp)