Skip to content

Commit

Permalink
add back pre-commit hook (commaai#33366)
Browse files Browse the repository at this point in the history
* add pre-commit

* space

* post

* e
  • Loading branch information
maxime-desroches authored Aug 23, 2024
1 parent 4d9ee68 commit b87414c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
7 changes: 7 additions & 0 deletions scripts/post-commit
Original file line number Diff line number Diff line change
@@ -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 ""
56 changes: 34 additions & 22 deletions tools/op.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -313,21 +323,22 @@ function op_default() {
echo -e "${BOLD}${UNDERLINE}Usage:${NC} op [OPTIONS] <COMMAND>"
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}"
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions tools/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit b87414c

Please sign in to comment.