diff --git a/telemetry/.clang-format b/telemetry/.clang-format new file mode 100644 index 000000000..66fc91b96 --- /dev/null +++ b/telemetry/.clang-format @@ -0,0 +1,7 @@ +# Options: https://clang.llvm.org/docs/ClangFormatStyleOptions.html +BasedOnStyle: Google +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +ColumnLimit: 80 +IndentWidth: 4 +UseTab: Never \ No newline at end of file diff --git a/telemetry/.githooks/pre-commit b/telemetry/.githooks/pre-commit new file mode 100644 index 000000000..36d515bd4 --- /dev/null +++ b/telemetry/.githooks/pre-commit @@ -0,0 +1,33 @@ +#!/bin/sh +set -e + +# Header +printf "\n" +printf "=====================================\n" +printf " FS-3 Telemetry Code Checks \n" +printf "=====================================\n" + +# Get staged files +FILES=$(git diff --cached --name-only --diff-filter=ACM) +FORMATTABLE_FILES=$(printf "%s\n" "$FILES" | grep -E '\.(c|cpp|h|hpp)$' || true) + +# Check if there are any files to format +if [ -z "$FORMATTABLE_FILES" ]; then + printf "āœ… No files to format. You're good to go!\n\n" + exit 0 +fi + +TOTAL=$(printf "%s\n" "$FORMATTABLE_FILES" | wc -l | tr -d ' ') + +# Format loops +INDEX=1 +printf "%s\n" "$FORMATTABLE_FILES" | while IFS= read -r FILE; do + TOOL="šŸŽØ clang-format" + clang-format -i "$FILE" >/dev/null 2>&1 + git add "$FILE" + printf "[%d/%d] %s: %s\n" "$INDEX" "$TOTAL" "$TOOL" "$FILE" + INDEX=$((INDEX + 1)) +done + +# Final message +printf "\nāœ… All formatted! Pre-commit complete.\n" diff --git a/telemetry/README.md b/telemetry/README.md new file mode 100644 index 000000000..e34a99456 --- /dev/null +++ b/telemetry/README.md @@ -0,0 +1,6 @@ +# FS-3 Telemetry + +## Setup (git hooks) +1. `chmod +x setup-hooks.sh` +2. `./setup-hooks.sh` +3. Go ahead and `git add ` and `git commit`! \ No newline at end of file diff --git a/telemetry/setup-hooks.sh b/telemetry/setup-hooks.sh new file mode 100644 index 000000000..2c855c9a9 --- /dev/null +++ b/telemetry/setup-hooks.sh @@ -0,0 +1,31 @@ +#!/bin/sh +set -e + +HOOK_SOURCE="telemetry/hooks/pre-commit" +HOOK_TARGET=".git/hooks/pre-commit" + +echo "šŸ› ļø FS-3 Telemetry: Pre-Commit Hook Setup" + +# Does source hook exist? +if [ ! -f "$HOOK_SOURCE" ]; then + echo "āŒ Error: Cannot find hook source at $HOOK_SOURCE" + exit 1 +fi + +# Create .git/hooks if needed +if [ ! -d ".git/hooks" ]; then + echo "šŸ“‚ Creating .git/hooks directory..." + mkdir -p .git/hooks +fi + +# Symlink the hook +echo "šŸ”— Linking $HOOK_SOURCE → $HOOK_TARGET" +ln -sf "../../$HOOK_SOURCE" "$HOOK_TARGET" + +# Make it executable +echo "šŸ”’ Making hook executable" +chmod +x "$HOOK_TARGET" + +# Finish up +echo "āœ… Pre-commit hook installed!" +echo "🚦 Try staging a file and running: git commit -m 'Test'" \ No newline at end of file