Skip to content

Commit

Permalink
move pre-commit logic to separate bash file, phetsims/perennial#404
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 18, 2024
1 parent da37cc7 commit daf7a48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions doc/phet-development-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions git-template-dir/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit daf7a48

Please sign in to comment.