From 3aed0bcea3d1705471e92fbba359aba4b095cf9a Mon Sep 17 00:00:00 2001 From: Spiker985 Date: Fri, 16 Dec 2022 16:57:17 -0500 Subject: [PATCH] Initial commit of hooks + manage_hook script --- hooks/HOW_TO_USE.md | 22 ++++++++++ hooks/manage_hooks-completion.bash | 33 ++++++++++++++ hooks/manage_hooks.sh | 69 ++++++++++++++++++++++++++++++ hooks/post-checkout | 24 +++++++++++ hooks/post-merge | 15 +++++++ hooks/update_editor.sh | 56 ++++++++++++++++++++++++ 6 files changed, 219 insertions(+) create mode 100644 hooks/HOW_TO_USE.md create mode 100644 hooks/manage_hooks-completion.bash create mode 100755 hooks/manage_hooks.sh create mode 100755 hooks/post-checkout create mode 100755 hooks/post-merge create mode 100755 hooks/update_editor.sh diff --git a/hooks/HOW_TO_USE.md b/hooks/HOW_TO_USE.md new file mode 100644 index 000000000..2b10f7e83 --- /dev/null +++ b/hooks/HOW_TO_USE.md @@ -0,0 +1,22 @@ +### Contents +| Filename | Description | +| - | - | +| post-checkout | This hook executes after a branch checkout, or branch switch has occurred. | +| post-merge | This hook executes after a branch merge has occurred | +| update_editor.sh | The actual brains of the hooks. Performs a yarn install, yarn build, yarn build:apm, and syncs all submodules. | + +### Usage +There are several ways to apply these hooks: +- You can manually copy the files over to the `/.git/hooks` folder and validate that they are executable - the effect should be immediate. This is the preferred option for Windows. +- You can use manage_hooks.sh to copy/symlink the hooks you choose. This is the preferred option for Linux/MacOS. + - Your mileage may vary on MacOS as it has not been tested outright, but should work in theory. + +### Instructions +- Open your favorite terminal +- Navigate to `/hooks`. + - IMPORTANT: The bash completions will only work within this directory, and are activated when using exactly `./manage-hooks.sh`. +- If you have bash-completions, source the `manage_hooks-completion.bash` file to allow for auto-complete ie `source manage_hooks-completion.bash`. +- Allow the auto-complete responses to guide you. +- Standard commands are `list`, `install` and `remove` +- The `install` and `remove` commands require the hook you wish to install, followed by an optional parameter for `hardlink` vs `symlink` with symlink being the default. + - A symbolically linked hook allows you to receive updates in the future. If you plan on adjusting your hook(s), you probably want to `hardlink` ie copy the files to the `/.git/hooks` directory diff --git a/hooks/manage_hooks-completion.bash b/hooks/manage_hooks-completion.bash new file mode 100644 index 000000000..d1d0bed14 --- /dev/null +++ b/hooks/manage_hooks-completion.bash @@ -0,0 +1,33 @@ +#!/bin/bash + +function __completion() { + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="list install remove" + + case ${COMP_CWORD} in + 1) + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + ;; + 2) + case ${prev} in + install) + COMPREPLY=( $(compgen -W "all $(ls --ignore='*.md' --ignore='*.sh' --ignore='*.bash')" -- ${cur}) ) + ;; + remove) + COMPREPLY=( $(compgen -W "all $(ls ../.git/hooks --ignore='*.sample')" -- ${cur}) ) + ;; + esac + ;; + 3) + case "${COMP_WORDS[COMP_CWORD-2]}" in + install) + COMPREPLY=( $(compgen -W "hardlink symbolic" -- ${cur}) ) + ;; + esac + ;; + esac +} + +complete -F __completion ./manage_hooks.sh diff --git a/hooks/manage_hooks.sh b/hooks/manage_hooks.sh new file mode 100755 index 000000000..e31cc57a1 --- /dev/null +++ b/hooks/manage_hooks.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +cd "$(dirname "$(readlink -f "$0")")" + +USAGEMSG="Usage: manage_hooks