Commit 3f7f83be authored by nanahira's avatar nanahira

Merge remote-tracking branch 'gh/test-sqlmerge' into develop

parents 361e6f14 fdd657d8
*.cdb merge=sqlite-merge diff=sqlite-diff
lflist.conf
*.sql
/bin
#!/bin/bash
# Input SQLite database path
DB="$1"
# Locate sqlite3 binary
if [ -n "$SQLITE3_BIN" ]; then
SQLITE3="$SQLITE3_BIN"
elif command -v sqlite3 >/dev/null 2>&1; then
SQLITE3="sqlite3"
elif command -v sqlite3.exe >/dev/null 2>&1; then
SQLITE3="sqlite3.exe"
elif [ -x "./bin/sqlite3" ]; then
SQLITE3="./bin/sqlite3"
elif [ -x "./bin/sqlite3.exe" ]; then
SQLITE3="./bin/sqlite3.exe"
else
echo "❌ Error: sqlite3 binary not found."
echo "Please set the SQLITE3_BIN environment variable or install sqlite3."
exit 1
fi
# Run .dump and filter out noise
"$SQLITE3" "$DB" .dump | grep -v '^--' | grep -v '^PRAGMA'
#!/bin/bash
# Locate sqlite3 binary
if [ -n "$SQLITE3_BIN" ]; then
SQLITE3="$SQLITE3_BIN"
elif command -v sqlite3 >/dev/null 2>&1; then
SQLITE3="sqlite3"
elif command -v sqlite3.exe >/dev/null 2>&1; then
SQLITE3="sqlite3.exe"
elif [ -x "./bin/sqlite3" ]; then
SQLITE3="./bin/sqlite3"
elif [ -x "./bin/sqlite3.exe" ]; then
SQLITE3="./bin/sqlite3.exe"
else
echo "❌ Error: sqlite3 binary not found."
echo "Please set the SQLITE3_BIN environment variable or install sqlite3."
exit 1
fi
BASE="$1"
OURS="$2"
THEIRS="$3"
RESULT="$2"
FILE_PATH="$5"
CONFLICT_FILE="$FILE_PATH.sql"
TMPDIR=$(mktemp -d) || exit 1
# 手动清理函数
cleanup() {
rm -rf "$TMPDIR"
}
# 不用 trap,因为 sh 没有 EXIT trap,靠手动调用
"$SQLITE3" "$BASE" .dump > "$TMPDIR/base.sql" || { cleanup; exit 1; }
"$SQLITE3" "$OURS" .dump > "$TMPDIR/ours.sql" || { cleanup; exit 1; }
"$SQLITE3" "$THEIRS" .dump > "$TMPDIR/theirs.sql" || { cleanup; exit 1; }
git merge-file -p "$TMPDIR/ours.sql" "$TMPDIR/base.sql" "$TMPDIR/theirs.sql" > "$TMPDIR/merged.sql"
MERGE_EXIT_CODE=$?
if grep '^<<<<<<<' "$TMPDIR/merged.sql" >/dev/null; then
echo "❌ Merge conflict detected. Please resolve:"
echo " --> $CONFLICT_FILE"
cp "$TMPDIR/merged.sql" "$CONFLICT_FILE"
cleanup
exit 1 # 保留冲突文件,人工处理,故不 cleanup
fi
rm -f "$RESULT"
"$SQLITE3" "$RESULT" < "$TMPDIR/merged.sql" || {
echo "❌ Failed to import merged SQL"
echo " --> $CONFLICT_FILE"
cp "$TMPDIR/merged.sql" "$CONFLICT_FILE"
cleanup
exit 1
}
echo "✅ Merged successfully to $FILE_PATH"
cleanup
exit 0
@echo off
setlocal enabledelayedexpansion
echo [INFO] Checking for sqlite3.exe...
REM 1. Try PATH
where sqlite3.exe >nul 2>nul
if %errorlevel%==0 (
echo [OK] Found sqlite3.exe in PATH
goto :gitconfig
)
REM 2. Try bin/sqlite3.exe
if exist "bin\sqlite3.exe" (
echo [OK] Found bin\sqlite3.exe
set "SQLITE3_BIN=bin\sqlite3.exe"
goto :gitconfig
)
REM 3. Not found — download
echo [INFO] sqlite3 not founddownloading...
set "ZIP_URL=https://sqlite.org/2025/sqlite-tools-win-x64-3490200.zip"
set "ZIP_FILE=bin\sqlite3.zip"
set "UNZIP_DIR=bin"
if not exist bin (
mkdir bin
)
echo [DOWNLOAD] Fetching SQLite...
curl -L -o "%ZIP_FILE%" "%ZIP_URL%"
if errorlevel 1 (
echo [ERROR] Failed to download sqlite3 zip.
exit /b 1
)
echo [UNZIP] Extracting...
unzip -o "%ZIP_FILE%" -d "%UNZIP_DIR%"
if errorlevel 1 (
echo [ERROR] Failed to unzip SQLite tools.
exit /b 1
)
if not exist "bin\sqlite3.exe" (
echo [ERROR] sqlite3.exe not found after extraction.
exit /b 1
)
set "SQLITE3_BIN=bin\sqlite3.exe"
echo [OK] sqlite3 installed to %SQLITE3_BIN%
:gitconfig
echo [CONFIG] Setting up Git merge driver...
git config merge.sqlite-merge.name "SQLite dump merge"
git config merge.sqlite-merge.driver "scripts/sqlite-merge.sh %%O %%A %%B %%L %%P"
echo [CONFIG] Setting up Git diff driver...
git config diff.sqlite-diff.textconv "scripts/sqlite-diff.sh"
git config diff.sqlite-diff.prompt false
echo [DONE] Git merge & diff drivers configured successfully.
exit /b 0
#!/bin/bash
set -e
# Attempt to find sqlite3, including environment override and local bin/
find_sqlite3() {
if [ -n "$SQLITE3_BIN" ] && [ -x "$SQLITE3_BIN" ]; then
echo "$SQLITE3_BIN"
return 0
fi
if command -v sqlite3 >/dev/null 2>&1; then
echo "sqlite3"
return 0
fi
if command -v sqlite3.exe >/dev/null 2>&1; then
echo "sqlite3.exe"
return 0
fi
if [ -x "./bin/sqlite3" ]; then
echo "./bin/sqlite3"
return 0
fi
if [ -x "./bin/sqlite3.exe" ]; then
echo "./bin/sqlite3.exe"
return 0
fi
return 1
}
install_sqlite3_windows() {
echo "🔍 sqlite3 not found — downloading for Windows..."
mkdir -p bin
ZIP_URL="https://sqlite.org/2025/sqlite-tools-win-x64-3490200.zip"
ZIP_FILE="bin/sqlite3.zip"
# Only download if the zip file or binaries aren't already there
if ! [ -f "$ZIP_FILE" ] || ! find bin -iname "sqlite3.exe" | grep -q .; then
echo "⬇️ Downloading SQLite tools..."
curl -sL -o "$ZIP_FILE" "$ZIP_URL" || {
echo "❌ Failed to download SQLite zip from $ZIP_URL"
exit 1
}
echo "📦 Extracting..."
unzip -o "$ZIP_FILE" -d bin || {
echo "❌ Failed to unzip SQLite tools"
exit 1
}
else
echo "✅ sqlite3 already exists in bin/, skipping download"
fi
}
# --- Main logic ---
SQLITE3_PATH=$(find_sqlite3)
if [ -z "$SQLITE3_PATH" ]; then
UNAME=$(uname | tr '[:upper:]' '[:lower:]')
if echo "$UNAME" | grep -qi "mingw\\|msys\\|cygwin"; then
install_sqlite3_windows
SQLITE3_PATH=$(find_sqlite3)
else
echo "❌ sqlite3 not found in PATH or ./bin/"
echo "Please install sqlite3 manually (e.g., via apt, brew, or your package manager)."
exit 1
fi
fi
echo "✅ Using sqlite3: $SQLITE3_PATH"
export SQLITE3_BIN="$SQLITE3_PATH"
# --- Git configuration ---
git config merge.sqlite-merge.name "SQLite dump merge"
git config merge.sqlite-merge.driver "scripts/sqlite-merge.sh %O %A %B %L %P"
git config diff.sqlite-diff.textconv "scripts/sqlite-diff.sh"
git config diff.sqlite-diff.prompt false
echo "✅ Git merge & diff drivers configured successfully."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment