Skip to content

Commit b78e07b

Browse files
committed
fix cl bug
1 parent 265ef66 commit b78e07b

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

.husky/pre-push

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ REMOTE_URL=$(git config --get remote.origin.url)
99
# Extract repo owner and name from remote URL
1010
# Handle both https://github.com/owner/repo.git and git@github.com:owner/repo.git
1111
if echo "$REMOTE_URL" | grep -q "github.com"; then
12-
REPO=$(echo "$REMOTE_URL" | sed -E 's|.*github.com[:/]([^/]+/[^/]+)(\.git)?$|\1|')
12+
REPO=$(echo "$REMOTE_URL" | sed -E 's|.*github.com[:/]([^/]+/[^/]+)|\1|' | sed 's|\.git||')
1313
else
1414
# If not a GitHub repo, exit silently
1515
exit 0
@@ -40,7 +40,11 @@ if ! git rev-list --count "$COMMIT_RANGE" >/dev/null 2>&1; then
4040
fi
4141

4242
# Get course.adoc files that were added or modified
43-
COURSE_FILES=$(git diff --name-only --diff-filter=AM "$COMMIT_RANGE" | grep "course\.adoc$" || true)
43+
# Separate newly added files from modified files
44+
NEW_COURSE_FILES=$(git diff --name-only --diff-filter=A "$COMMIT_RANGE" | grep "course\.adoc$" || true)
45+
MODIFIED_COURSE_FILES=$(git diff --name-only --diff-filter=M "$COMMIT_RANGE" | grep "course\.adoc$" || true)
46+
COURSE_FILES="$NEW_COURSE_FILES $MODIFIED_COURSE_FILES"
47+
COURSE_FILES=$(echo "$COURSE_FILES" | tr -s ' ' | sed 's/^ *//;s/ *$//')
4448

4549
if [ -z "$COURSE_FILES" ]; then
4650
# No course.adoc files modified, exit silently
@@ -62,13 +66,29 @@ for COURSE_FILE in $COURSE_FILES; do
6266
BASE_REF=$(echo "$COMMIT_RANGE" | sed 's/\.\..*//')
6367
BASE_COMMIT=$(git rev-parse "$BASE_REF" 2>/dev/null || echo "")
6468

69+
# Check if this is a newly created file
70+
IS_NEW_FILE=false
71+
if echo "$NEW_COURSE_FILES" | grep -q "^$COURSE_FILE$"; then
72+
IS_NEW_FILE=true
73+
elif [ -z "$BASE_COMMIT" ] || ! git cat-file -e "$BASE_COMMIT:$COURSE_FILE" 2>/dev/null; then
74+
# File doesn't exist in base, it's new
75+
IS_NEW_FILE=true
76+
fi
77+
6578
# Check if :status: active was ADDED in the changes (release)
6679
# Look for additions of ":status: active" in the diff
67-
STATUS_ADDED=$(git diff "$COMMIT_RANGE" -- "$COURSE_FILE" | grep -c "^+.*:status:[[:space:]]*active" || echo "0")
68-
69-
if [ "$STATUS_ADDED" -gt 0 ]; then
80+
if git diff "$COMMIT_RANGE" -- "$COURSE_FILE" 2>/dev/null | grep -q "^+.*:status:[[:space:]]*active"; then
7081
# Status active was added in this change - it's a release
7182
FOUND_RELEASE=true
83+
elif [ "$IS_NEW_FILE" = true ]; then
84+
# File is newly created
85+
if grep -q "^:status:[[:space:]]*active" "$COURSE_FILE"; then
86+
# New file with active status - treat as release
87+
FOUND_RELEASE=true
88+
else
89+
# New file without active status - it's a draft
90+
FOUND_DRAFT=true
91+
fi
7292
elif [ -n "$BASE_COMMIT" ] && git cat-file -e "$BASE_COMMIT:$COURSE_FILE" 2>/dev/null; then
7393
# File existed before, check if it had active status
7494
BASE_HAS_ACTIVE=$(git show "$BASE_COMMIT:$COURSE_FILE" 2>/dev/null | grep -q "^:status:[[:space:]]*active" && echo "yes" || echo "no")
@@ -77,19 +97,9 @@ for COURSE_FILE in $COURSE_FILES; do
7797
if [ "$BASE_HAS_ACTIVE" = "yes" ] && [ "$CURRENT_HAS_ACTIVE" = "yes" ]; then
7898
# Status was already active and still is - this is a fix
7999
FOUND_FIX=true
80-
else
81-
# No active status, it's a draft
82-
FOUND_DRAFT=true
83-
fi
84-
else
85-
# File is new or we can't determine base, check current status
86-
if grep -q "^:status:[[:space:]]*active" "$COURSE_FILE"; then
87-
# New file with active status - treat as release
88-
FOUND_RELEASE=true
89-
else
90-
# New file without active status - it's a draft
91-
FOUND_DRAFT=true
92100
fi
101+
# If file existed but doesn't have active status, don't suggest anything
102+
# (it's a modification to a draft course, but not a new draft)
93103
fi
94104
done
95105

0 commit comments

Comments
 (0)