From 189260323102c7e184c6b177668dd27f9d23a186 Mon Sep 17 00:00:00 2001 From: Omer Tuchfeld Date: Wed, 7 Aug 2024 10:51:39 +0200 Subject: [PATCH] hooks: pre-commit hook to duplicate file We have a file that's always a duplicate of another file, until we can get rid of this requirement a pre-commit hook to take care of it would be nice Signed-off-by: Omer Tuchfeld --- README.md | 12 ++++++++++++ hooks/pre-commit | 13 +++++++++++++ install-hooks.sh | 8 ++++++++ 3 files changed, 33 insertions(+) create mode 100755 hooks/pre-commit create mode 100755 install-hooks.sh diff --git a/README.md b/README.md index 00c24ce9..4679efc9 100644 --- a/README.md +++ b/README.md @@ -56,3 +56,15 @@ currently built images are tracked in ## [Training](./training/README.md) Linux Operating System Bootable containers enabled for AI Training + +## Setting Up Git Hooks + +To install our standard git hooks, run the following command: + +```sh +./install-hooks.sh +``` + +### pre-commit hook + +Ensures that `training/ilab-wrapper/ilab` is duplicated into `training/nvidia-bootc/duplicated/ilab-wrapper/ilab` diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 00000000..45140eec --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,13 @@ +#!/bin/bash + +SOURCE_FILE="training/ilab-wrapper/ilab" +DEST_FILE="training/nvidia-bootc/duplicated/ilab-wrapper/ilab" + +if [[ -f "$SOURCE_FILE" ]]; then + mkdir -p "$(dirname "$DEST_FILE")" + cp "$SOURCE_FILE" "$DEST_FILE" + git add "$DEST_FILE" +else + echo "Source file $SOURCE_FILE does not exist. Aborting commit." + exit 1 +fi diff --git a/install-hooks.sh b/install-hooks.sh new file mode 100755 index 00000000..2c04220c --- /dev/null +++ b/install-hooks.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +HOOKS_DIR="hooks" +GIT_HOOKS_DIR=".git/hooks" + +cp "$HOOKS_DIR/pre-commit" "$GIT_HOOKS_DIR/pre-commit" + +echo "Hooks installed successfully."