Files
soul-yongping/.cursor/scripts/gitea-sync.sh
卡若 80e397f7ac feat: 运营-用户功能四大需求完整实现
1. 客资中心:Dashboard 聚合 CKB 线索+提交记录,联表用户信息
2. @置顶:Person 三端(后端+管理端+小程序)置顶功能,首页优先展示
3. 存客宝场景:一键检查并自动启用所有场景获客计划
4. 去重增强:后端聚合 dupCount,管理端展示重复标记和统计
5. 首页文案:"最新更新"→"推荐","开始阅读"→"点击阅读"

Made-with: Cursor
2026-03-19 16:20:46 +08:00

47 lines
1.9 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 与 Gitea192.168.1.201)双向同步:先拉取,有本地变更则提交并推送
# 可手动执行,也可由 launchd 每 10 分钟执行
set -e
REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
REMOTE="gitea-local"
LOG_FILE="$REPO_ROOT/.cursor/scripts/gitea-sync.log"
cd "$REPO_ROOT"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"; }
log "--- sync start (branch=$BRANCH, remote=$REMOTE) ---"
# 1. 拉取远程更新(若有未提交变更则先 stashpull 后再 pop
STASHED=""
if [ -n "$(git status -s)" ]; then
git stash push -u -m "gitea-sync $(date +%s)" 2>/dev/null && STASHED=1 || true
fi
git fetch "$REMOTE" 2>&1 | tee -a "$LOG_FILE" || true
if git ls-remote --exit-code --heads "$REMOTE" "$BRANCH" &>/dev/null; then
git pull "$REMOTE" "$BRANCH" --no-edit 2>&1 | tee -a "$LOG_FILE" || log "pull 失败或冲突,继续尝试推送本地变更"
fi
[ -n "$STASHED" ] && git stash pop 2>/dev/null || true
# 2. 若有本地未提交变更,则提交并推送
STATUS=$(git status -s)
if [ -n "$STATUS" ]; then
git add -A
git commit -m "sync: $(date '+%Y-%m-%d %H:%M')" 2>&1 | tee -a "$LOG_FILE" || log "commit failed (nothing to commit or conflict)"
git push "$REMOTE" "$BRANCH" 2>&1 | tee -a "$LOG_FILE" || log "push failed"
else
# 若有已提交但未推送的提交,也推送(仅当远程有此分支且本地比远程多提交时)
if git ls-remote --exit-code --heads "$REMOTE" "$BRANCH" &>/dev/null; then
AHEAD=$(git rev-list "refs/remotes/${REMOTE}/${BRANCH}"..HEAD --count 2>/dev/null || echo 0)
if [ "${AHEAD:-0}" -gt 0 ]; then
git push "$REMOTE" "$BRANCH" 2>&1 | tee -a "$LOG_FILE" || log "push failed"
fi
else
git push -u "$REMOTE" "$BRANCH" 2>&1 | tee -a "$LOG_FILE" || log "push (new branch) failed"
fi
fi
log "--- sync end ---"