From daf7a487fbc87625e398a90ada977e917f49cd78 Mon Sep 17 00:00:00 2001 From: Michael Kauzmann Date: Mon, 18 Nov 2024 13:06:38 -0700 Subject: [PATCH] move pre-commit logic to separate bash file, https://github.com/phetsims/perennial/issues/404 --- doc/phet-development-overview.md | 6 +++--- git-template-dir/hooks/pre-commit | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/doc/phet-development-overview.md b/doc/phet-development-overview.md index c96024a9..1131329f 100644 --- a/doc/phet-development-overview.md +++ b/doc/phet-development-overview.md @@ -84,7 +84,7 @@ Method 1 (recommended): Get all PhET repos * Change directory to phetsims: `cd phetsims` * Get [phetsims/perennial](https://github.com/phetsims/perennial): `git clone https://github.com/phetsims/perennial` -* Run "clone-missing-repos.sh": `./perennial/bin/clone-missing-repos.sh` +* Run "clone-missing-repos.sh": `./perennial-alias/bin/clone-missing-repos.sh` Method 2: Manually get specific PhET repos @@ -475,8 +475,8 @@ https://github.com/phetsims/chipper/blob/main/js/initialize-globals.js 13. Install PhET's git hooks to run basic checks as part of the git lifecycle. Run this from the root of your checkout. First it clears any pre-existing commit hooks, then installs the new hooks. -``` -perennial/bin/for-each.sh perennial/data/active-repos "rm .git/hooks/pre-commit; git init --template=../phet-info/git-template-dir" +```sh +perennial-alias/bin/for-each.sh perennial-alias/data/active-repos "rm .git/hooks/pre-commit; git init --template=../phet-info/git-template-dir" ``` Getting to optimal performance on all supported platforms can be tricky--this section enumerates possible optimizations diff --git a/git-template-dir/hooks/pre-commit b/git-template-dir/hooks/pre-commit index 41446e26..df580ab5 100755 --- a/git-template-dir/hooks/pre-commit +++ b/git-template-dir/hooks/pre-commit @@ -1,15 +1,17 @@ #!/bin/bash #----------------------------------------------------------------------------------------------------------------------- -# git pre-commit hooks +# git pre-commit hooks for the PhET Codebase. These are installed on all repos. +# +# This script only launches another bash script, and new logic should NOT be added here. This way, changes can be made +# without the need to reinstall git hooks across all repos. # # Please see https://github.com/phetsims/phet-info/blob/main/doc/phet-development-overview.md#utilities-and-instrumentation-for-development-and-testing # for installation instructions. #----------------------------------------------------------------------------------------------------------------------- -# Detect the current branch. Requires git 2.22.0 or higher -current_branch=$(git branch --show-current) +PRE_COMMIT_SCRIPT="../perennial-alias/bin/hook-launcher-pre-commit.sh" -# Only run pre-commit hooks in main, see https://github.com/phetsims/perennial/issues/276 -if [[ "$current_branch" == "main" ]]; then - ../perennial-alias/bin/sage run ../chipper/js/scripts/hook-pre-commit.js +# only run the file if it exists. This helps with backwards compatibility if on an older version of perennial-alias. +if test -f "$PRE_COMMIT_SCRIPT"; then + $PRE_COMMIT_SCRIPT fi