| 1 | #!/usr/bin/env sh |
| 2 | # Rebuild dist/ after a commit that touched the extension. |
| 3 | # |
| 4 | # The browser loads dist/, never extension/, so an edit under extension/ does |
| 5 | # nothing until build.sh runs. Committing is the moment you believe the edit is |
| 6 | # finished, which makes it the right moment to put it where the browser can see |
| 7 | # it. Nothing here reloads the sidebar — that is still a click. |
| 8 | # |
| 9 | # Enable it once per clone: |
| 10 | # |
| 11 | # git config core.hooksPath .githooks |
| 12 | # |
| 13 | # Hooks are not versioned in .git/hooks, so this directory is the copy that |
| 14 | # travels with the repo and that config line is what points git at it. |
| 15 | set -eu |
| 16 | |
| 17 | root=$(git rev-parse --show-toplevel) |
| 18 | |
| 19 | # Only the extension half is built here, so only its files are worth a rebuild. |
| 20 | # --root makes the first commit in a repo list its files instead of nothing. |
| 21 | if ! git diff-tree --no-commit-id --name-only -r --root HEAD | grep -q '^extension/'; then |
| 22 | exit 0 |
| 23 | fi |
| 24 | |
| 25 | # build.sh ends with a paragraph about loading the unpacked extension, which is |
| 26 | # not news to someone who already has it loaded. Kept only if the build fails. |
| 27 | if out=$("$root/build.sh" 2>&1); then |
| 28 | echo "post-commit: rebuilt dist/chrome and dist/firefox" |
| 29 | else |
| 30 | echo "post-commit: build.sh failed" >&2 |
| 31 | echo "$out" >&2 |
| 32 | fi |
| 33 | |
| 34 | # A failed build must not read as a failed commit: the commit already happened. |
| 35 | exit 0 |