diff --git a/packages/mosaic/framework/tools/_scripts/mosaic-sync-skills b/packages/mosaic/framework/tools/_scripts/mosaic-sync-skills index 4958374..45ea77d 100755 --- a/packages/mosaic/framework/tools/_scripts/mosaic-sync-skills +++ b/packages/mosaic/framework/tools/_scripts/mosaic-sync-skills @@ -55,7 +55,26 @@ mkdir -p "$MOSAIC_HOME" "$MOSAIC_SKILLS_DIR" "$MOSAIC_LOCAL_SKILLS_DIR" if [[ $fetch -eq 1 ]]; then if [[ -d "$SKILLS_REPO_DIR/.git" ]]; then echo "[mosaic-skills] Updating skills source: $SKILLS_REPO_DIR" - git -C "$SKILLS_REPO_DIR" pull --rebase + + # Stash any local changes (dirty index or worktree) before pulling + local_changes=0 + if ! git -C "$SKILLS_REPO_DIR" diff --quiet 2>/dev/null || \ + ! git -C "$SKILLS_REPO_DIR" diff --cached --quiet 2>/dev/null; then + local_changes=1 + echo "[mosaic-skills] Stashing local changes..." + git -C "$SKILLS_REPO_DIR" stash push -q -m "mosaic-sync-skills auto-stash" + fi + + if ! git -C "$SKILLS_REPO_DIR" pull --rebase; then + echo "[mosaic-skills] WARN: pull failed — continuing with existing checkout" >&2 + fi + + # Restore stashed changes + if [[ $local_changes -eq 1 ]]; then + echo "[mosaic-skills] Restoring local changes..." + git -C "$SKILLS_REPO_DIR" stash pop -q 2>/dev/null || \ + echo "[mosaic-skills] WARN: stash pop had conflicts — check $SKILLS_REPO_DIR" >&2 + fi else echo "[mosaic-skills] Cloning skills source to: $SKILLS_REPO_DIR" mkdir -p "$(dirname "$SKILLS_REPO_DIR")"