28 lines
828 B
Bash
Executable File
28 lines
828 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
REPO_DIR="/workspaces"
|
|
HOOK_DIR="$REPO_DIR/.git/hooks"
|
|
META_DIR="/tmp/git-metadata"
|
|
|
|
if [[ ! -d "$REPO_DIR/.git" ]]; then
|
|
echo "No Git repository found in $REPO_DIR; skipping hook install"
|
|
exit 0
|
|
fi
|
|
|
|
mkdir -p "$HOOK_DIR" "$META_DIR"
|
|
|
|
cat <<'HOOK' > "$HOOK_DIR/post-commit"
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
META_DIR=/tmp/git-metadata
|
|
mkdir -p "$META_DIR"
|
|
|
|
git branch --show-current > "$META_DIR/current-branch" 2>/dev/null || echo "main" > "$META_DIR/current-branch"
|
|
git rev-parse HEAD > "$META_DIR/commit-hash" 2>/dev/null || echo "unknown" > "$META_DIR/commit-hash"
|
|
git remote get-url origin > "$META_DIR/remote-url" 2>/dev/null || echo "no-remote" > "$META_DIR/remote-url"
|
|
HOOK
|
|
chmod +x "$HOOK_DIR/post-commit"
|
|
|
|
echo "Git post-commit hook installed for metadata capture."
|