mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-02 11:45:20 +02:00
fix: setup runs pending migrations so git pull + ./setup works
Previously, version migrations only ran during /gstack-upgrade (Step 4.75). Users who updated via git pull + ./setup never got migrations applied, leaving stale skill directory structures in place. Now setup tracks the last-run version in ~/.gstack/.last-setup-version and runs any pending migrations automatically. Addresses adversarial review findings: space-safe while-read loop, fresh install guard, upper-bound version check, missing VERSION guard.
This commit is contained in:
@@ -710,17 +710,25 @@ MIGRATIONS_DIR="$SOURCE_GSTACK_DIR/gstack-upgrade/migrations"
|
||||
CURRENT_VERSION=$(cat "$SOURCE_GSTACK_DIR/VERSION" 2>/dev/null || echo "unknown")
|
||||
LAST_SETUP_VERSION=$(cat "$HOME/.gstack/.last-setup-version" 2>/dev/null || echo "0.0.0.0")
|
||||
if [ -d "$MIGRATIONS_DIR" ] && [ "$CURRENT_VERSION" != "unknown" ] && [ "$LAST_SETUP_VERSION" != "$CURRENT_VERSION" ]; then
|
||||
for migration in $(find "$MIGRATIONS_DIR" -maxdepth 1 -name 'v*.sh' -type f 2>/dev/null | sort -V); do
|
||||
m_ver="$(basename "$migration" .sh | sed 's/^v//')"
|
||||
# Run if this migration version is newer than last setup version
|
||||
if [ "$(printf '%s\n%s' "$LAST_SETUP_VERSION" "$m_ver" | sort -V | head -1)" = "$LAST_SETUP_VERSION" ] && [ "$LAST_SETUP_VERSION" != "$m_ver" ]; then
|
||||
echo " running migration $m_ver..."
|
||||
bash "$migration" || echo " warning: migration $m_ver had errors (non-fatal)"
|
||||
fi
|
||||
done
|
||||
# Fresh install (no marker file) — skip migrations, just write marker
|
||||
if [ ! -f "$HOME/.gstack/.last-setup-version" ]; then
|
||||
: # fall through to marker write below
|
||||
else
|
||||
find "$MIGRATIONS_DIR" -maxdepth 1 -name 'v*.sh' -type f 2>/dev/null | sort -V | while IFS= read -r migration; do
|
||||
m_ver="$(basename "$migration" .sh | sed 's/^v//')"
|
||||
# Run if migration is newer than last setup version AND not newer than current version
|
||||
if [ "$(printf '%s\n%s' "$LAST_SETUP_VERSION" "$m_ver" | sort -V | head -1)" = "$LAST_SETUP_VERSION" ] && [ "$LAST_SETUP_VERSION" != "$m_ver" ] \
|
||||
&& [ "$(printf '%s\n%s' "$m_ver" "$CURRENT_VERSION" | sort -V | tail -1)" = "$CURRENT_VERSION" ]; then
|
||||
echo " running migration $m_ver..."
|
||||
bash "$migration" || echo " warning: migration $m_ver had errors (non-fatal)"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
mkdir -p "$HOME/.gstack"
|
||||
echo "$CURRENT_VERSION" > "$HOME/.gstack/.last-setup-version"
|
||||
if [ "$CURRENT_VERSION" != "unknown" ]; then
|
||||
echo "$CURRENT_VERSION" > "$HOME/.gstack/.last-setup-version"
|
||||
fi
|
||||
|
||||
# 9. First-time welcome + legacy cleanup
|
||||
if [ ! -f "$HOME/.gstack/.welcome-seen" ]; then
|
||||
|
||||
Reference in New Issue
Block a user