55 lines
1.2 KiB
Bash
Executable File
55 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
if [ "${GITNEXUS_AUTO_REFRESH:-1}" = "0" ]; then
|
|
echo "GitNexus auto refresh disabled by GITNEXUS_AUTO_REFRESH=0"
|
|
exit 0
|
|
fi
|
|
|
|
repo_root=$(git rev-parse --show-toplevel 2>/dev/null) || {
|
|
echo "Not inside a git repository"
|
|
exit 1
|
|
}
|
|
cd "$repo_root"
|
|
|
|
git_dir=$(git rev-parse --git-dir)
|
|
case "$git_dir" in
|
|
/*) ;;
|
|
*) git_dir="$repo_root/$git_dir" ;;
|
|
esac
|
|
|
|
head_commit=$(git rev-parse HEAD 2>/dev/null || true)
|
|
if [ -z "$head_commit" ]; then
|
|
echo "No HEAD commit found; skip GitNexus refresh"
|
|
exit 0
|
|
fi
|
|
|
|
stamp_file="$git_dir/gitnexus-indexed-head"
|
|
lock_dir="$git_dir/gitnexus-refresh.lock"
|
|
|
|
if [ -f "$stamp_file" ] && [ "$(cat "$stamp_file" 2>/dev/null || true)" = "$head_commit" ]; then
|
|
echo "GitNexus index already refreshed for $head_commit"
|
|
exit 0
|
|
fi
|
|
|
|
if ! mkdir "$lock_dir" 2>/dev/null; then
|
|
echo "GitNexus refresh already running; skip"
|
|
exit 0
|
|
fi
|
|
|
|
cleanup() {
|
|
rmdir "$lock_dir" 2>/dev/null || true
|
|
}
|
|
trap cleanup EXIT HUP INT TERM
|
|
|
|
echo "GitNexus refresh started for $head_commit"
|
|
|
|
if npx gitnexus analyze --index-only --name anxinyan .; then
|
|
printf '%s\n' "$head_commit" > "$stamp_file"
|
|
echo "GitNexus refresh completed for $head_commit"
|
|
else
|
|
status=$?
|
|
echo "GitNexus refresh failed with exit code $status"
|
|
exit "$status"
|
|
fi
|