Commit 9ac84288 by liimin

fix(ci): add post-commit fix-git-refs script for Windows branch ref bug

1 parent e8015024
...@@ -9,15 +9,7 @@ pre-commit: ...@@ -9,15 +9,7 @@ pre-commit:
post-commit: post-commit:
commands: commands:
fix-refs: fix-refs:
run: | run: sh scripts/fix-git-refs.sh
BRANCH=$(git symbolic-ref HEAD 2>/dev/null | sed 's|refs/heads/||');
if [ -n "$BRANCH" ]; then
NEW_HASH=$(tail -1 .git/logs/refs/heads/$BRANCH 2>/dev/null | cut -d' ' -f2);
if [ -n "$NEW_HASH" ]; then
mkdir -p .git/refs/heads/$(dirname $BRANCH) 2>/dev/null;
printf '%s\n' "$NEW_HASH" > .git/refs/heads/$BRANCH;
fi
fi
post-merge: post-merge:
commands: commands:
......
#!/bin/sh
# Fix Windows/Git branch ref sync bug
# On Windows, git commit may fail to update loose refs properly,
# causing branch refs to fall back to stale packed-refs values.
# This script reads the correct hash from the reflog and writes it
# to the loose ref file, ensuring branch refs stay in sync.
GIT_DIR="$(git rev-parse --git-dir 2>/dev/null)"
if [ -z "$GIT_DIR" ]; then
exit 0
fi
BRANCH="$(git symbolic-ref HEAD 2>/dev/null | sed 's|refs/heads/||')"
if [ -z "$BRANCH" ]; then
exit 0
fi
REFLOG="$GIT_DIR/logs/refs/heads/$BRANCH"
if [ -f "$REFLOG" ]; then
NEW_HASH="$(tail -1 "$REFLOG" | cut -d' ' -f2)"
else
NEW_HASH="$(tail -1 "$GIT_DIR/logs/HEAD" | cut -d' ' -f2)"
fi
if [ -z "$NEW_HASH" ]; then
exit 0
fi
REF_FILE="$GIT_DIR/refs/heads/$BRANCH"
REF_DIR="$(dirname "$REF_FILE")"
mkdir -p "$REF_DIR" 2>/dev/null
printf '%s\n' "$NEW_HASH" > "$REF_FILE"
...@@ -204,3 +204,4 @@ ...@@ -204,3 +204,4 @@
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!