Skip to content

Commit 45a86a5

Browse files
committed
chore: Update git hooks script
1 parent bbba3f2 commit 45a86a5

File tree

1 file changed

+71
-40
lines changed

1 file changed

+71
-40
lines changed

tools/server/webui/scripts/install-git-hooks.sh

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ if git diff --cached --name-only | grep -q "^tools/server/webui/"; then
4242
# Check if lint command succeeded
4343
if [ $? -ne 0 ]; then
4444
echo "Error: npm run lint failed"
45-
if [ $STASH_CREATED -eq 0 ]; then
46-
echo "You can restore your unstaged changes with: git stash pop"
47-
fi
4845
exit 1
4946
fi
5047
@@ -70,9 +67,11 @@ EOF
7067
cat > "$PRE_PUSH_HOOK" << 'EOF'
7168
#!/bin/bash
7269
73-
# Check if there are any changes in the webui directory that need building
74-
if git diff --name-only HEAD~1..HEAD | grep -q "^tools/server/webui/" || git diff --name-only --cached | grep -q "^tools/server/webui/"; then
75-
echo "Building webui for push..."
70+
# Check if there are any webui changes that need building
71+
WEBUI_CHANGES=$(git diff --name-only @{push}..HEAD | grep "^tools/server/webui/" || true)
72+
73+
if [ -n "$WEBUI_CHANGES" ]; then
74+
echo "Webui changes detected, checking if build is up-to-date..."
7675
7776
# Change to webui directory
7877
cd tools/server/webui
@@ -83,48 +82,80 @@ if git diff --name-only HEAD~1..HEAD | grep -q "^tools/server/webui/" || git dif
8382
exit 1
8483
fi
8584
86-
# Stash any unstaged changes to avoid conflicts during build
87-
echo "Checking for unstaged changes..."
88-
if ! git diff --quiet || ! git diff --cached --quiet --diff-filter=A; then
89-
echo "Stashing unstaged changes..."
90-
git stash push --include-untracked -m "Pre-push hook: stashed unstaged changes"
91-
STASH_CREATED=$?
85+
# Check if build output exists and is newer than source files
86+
BUILD_FILE="../public/index.html.gz"
87+
NEEDS_BUILD=false
88+
89+
if [ ! -f "$BUILD_FILE" ]; then
90+
echo "Build output not found, building..."
91+
NEEDS_BUILD=true
9292
else
93-
echo "No unstaged changes to stash"
94-
STASH_CREATED=1
93+
# Check if any source files are newer than the build output
94+
if find src -newer "$BUILD_FILE" -type f | head -1 | grep -q .; then
95+
echo "Source files are newer than build output, rebuilding..."
96+
NEEDS_BUILD=true
97+
fi
9598
fi
9699
97-
# Run the build command
98-
npm run build
99-
100-
# Check if build command succeeded
101-
if [ $? -ne 0 ]; then
102-
echo "Error: npm run build failed"
103-
if [ $STASH_CREATED -eq 0 ]; then
104-
echo "You can restore your unstaged changes with: git stash pop"
100+
if [ "$NEEDS_BUILD" = true ]; then
101+
echo "Building webui..."
102+
103+
# Stash any unstaged changes to avoid conflicts during build
104+
echo "Checking for unstaged changes..."
105+
if ! git diff --quiet || ! git diff --cached --quiet --diff-filter=A; then
106+
echo "Stashing unstaged changes..."
107+
git stash push --include-untracked -m "Pre-push hook: stashed unstaged changes"
108+
STASH_CREATED=$?
109+
else
110+
echo "No unstaged changes to stash"
111+
STASH_CREATED=1
112+
fi
113+
114+
# Run the build command
115+
npm run build
116+
117+
# Check if build command succeeded
118+
if [ $? -ne 0 ]; then
119+
echo "Error: npm run build failed"
120+
if [ $STASH_CREATED -eq 0 ]; then
121+
echo "You can restore your unstaged changes with: git stash pop"
122+
fi
123+
exit 1
105124
fi
106-
exit 1
107-
fi
108125
109-
# Go back to repo root to add build output
110-
cd ../../..
111-
112-
# Add the build output to staging area and commit if there are changes
113-
if [ -f "tools/server/public/index.html.gz" ]; then
114-
git add tools/server/public/index.html.gz
115-
if ! git diff --cached --quiet; then
116-
git commit -m "chore: update webui build output"
126+
# Go back to repo root
127+
cd ../../..
128+
129+
# Check if build output was created/updated
130+
if [ -f "tools/server/public/index.html.gz" ]; then
131+
# Add the build output and commit it
132+
git add tools/server/public/index.html.gz
133+
if ! git diff --cached --quiet; then
134+
echo "Committing updated build output..."
135+
git commit -m "chore: update webui build output"
136+
echo "✅ Build output committed successfully"
137+
else
138+
echo "Build output unchanged"
139+
fi
140+
else
141+
echo "Error: Build output not found after build"
142+
if [ $STASH_CREATED -eq 0 ]; then
143+
echo "You can restore your unstaged changes with: git stash pop"
144+
fi
145+
exit 1
117146
fi
147+
148+
if [ $STASH_CREATED -eq 0 ]; then
149+
echo "✅ Build completed. Your unstaged changes have been stashed."
150+
echo "They will be automatically restored after the push."
151+
# Create a marker file to indicate stash was created by pre-push hook
152+
touch .git/WEBUI_PUSH_STASH_MARKER
153+
fi
154+
else
155+
echo "✅ Build output is up-to-date"
118156
fi
119157
120-
if [ $STASH_CREATED -eq 0 ]; then
121-
echo "✅ Build completed. Your unstaged changes have been stashed."
122-
echo "They will be automatically restored after the push."
123-
# Create a marker file to indicate stash was created by pre-push hook
124-
touch .git/WEBUI_PUSH_STASH_MARKER
125-
fi
126-
127-
echo "✅ Webui build completed successfully"
158+
echo "✅ Webui ready for push"
128159
fi
129160
130161
exit 0

0 commit comments

Comments
 (0)