Skip to content
Samuel Voeller edited this page Aug 24, 2022 · 5 revisions

Amethyst Githooked - githooked - xCykrix

Table of Contents

Installation

Module Path: https://raw.githubusercontent.com/amethyst-studio/githooked/main/mod.ts

Versioned Path: https://raw.githubusercontent.com/amethyst-studio/githooked/COMMIT_HASH/main/mod.ts

Command Line Usage

Please use one of the following to install githooked. These provide you with different options for controlling the version utilized. You need to call this once when the repository is cloned.

deno run --no-check=remote --allow-run=deno,git --allow-read --allow-write=.git-hooks https://deno.land/x/githooked/mod.ts install
deno run --no-check=remote --allow-run=deno,git --allow-read --allow-write=.git-hooks https://raw.githubusercontent.com/amethyst-studio/githooked/main/mod.ts install
deno run --no-check=remote --allow-run=deno,git --allow-read --allow-write=.git-hooks https://raw.githubusercontent.com/amethyst-studio/githooked/COMMIT_HASH/mod.ts install

Create a Script

Creating a script with githooked is designed to be a simple, straightforward, and consistent process. To begin creating a script, please review the git hooks list available with Git-SCM. For our example, we will create a pre-commit hook that will require source code tests to pass.

  1. Create a file named pre-commit in the .git-hooks folder. This file will be generated on the first install.
  2. If needed, use the following template to prepare the file.
#!/usr/bin/env bash

# Configure the hook with these options.
HOOK_DEBUG=0          # Set to 1 to enable debug mode. This will print additional output.
HOOK_DISABLE_NOTICE=0 # Set to 1 to disable the notice when the hook exits with an error code.

# Import the git-hooked wrapper to prepare the env and execute the script below.
. "$(dirname "$0")/_util/git-hooked.sh"

# Your script begins here.
# The last command to run, or explicit "exit" commands, will determine the status code to Git.

# echo "Placeholder git-hook for pre-commit."

exit 0
  1. Add the validation code between "Your script begins here." and the "exit 0". For this example, we will use a Deno task.
# Your script begins here.
# The last command to run, or explicit "exit" commands, will determine the status code to Git.

deno run test

exit 0
  1. Add files and run a commit. You should now see the commands defined above have been executed.