Bladeren bron

Update git_sync.sh script

steven_roc 3 dagen geleden
bovenliggende
commit
b00ecb8d48
1 gewijzigde bestanden met toevoegingen van 24 en 44 verwijderingen
  1. 24 44
      scripts/git_sync.sh

+ 24 - 44
scripts/git_sync.sh

@@ -2,7 +2,7 @@
 # ============================================================
 # Git Auto Sync Script
 # ============================================================
-# This script configures and pushes code to Gogs repository
+# 自动同步代码到 Gogs 仓库
 # ============================================================
 
 set -e
@@ -12,69 +12,49 @@ REPO_NAME="hikvision-isup-client"
 ACCESS_TOKEN="1942ce3d6478f7a572fee3dd4891e49f6c416aad"
 FULL_URL="${GOGS_URL}/${REPO_NAME}.git"
 
-echo "=== Git Repository Setup ==="
+echo "=== Git Repository Sync ==="
 echo ""
 
-# Check if git is installed
+# 检查 git
 if ! command -v git &> /dev/null; then
-    echo "Git is not installed. Installing..."
-    sudo apt-get install -y git
+    echo "Error: git is not installed"
+    exit 1
 fi
 
-# Initialize git repository if not already initialized
+# 初始化仓库(如果尚未初始化)
 if [ ! -d ".git" ]; then
-    echo "[1/4] Initializing git repository..."
+    echo "[1/5] Initializing git repository..."
     git init
     git branch -M main
-    echo "Git repository initialized"
-else
-    echo "[1/4] Git repository already exists"
 fi
 
-# Add remote origin with access token
-echo "[2/4] Configuring remote origin..."
-# Remove existing remote if exists
-git remote remove origin 2>/dev/null || true
-# Add remote with credentials in URL
-git remote add origin "https://steven_roc:${ACCESS_TOKEN}@git.zhonjin.com:40717/steven_roc/${REPO_NAME}.git"
-echo "Remote origin added: ${FULL_URL}"
+# 配置用户
+git config user.name "steven_roc" 2>/dev/null || true
+git config user.email "steven_roc@zhonjin.com" 2>/dev/null || true
 
-# Configure git user (if not already configured)
-if ! git config user.name &> /dev/null || [ "$(git config user.name)" = "" ]; then
-    git config user.name "steven_roc"
-fi
-if ! git config user.email &> /dev/null || [ "$(git config user.email)" = "" ]; then
-    git config user.email "steven_roc@zhonjin.com"
+# 添加远程仓库
+if ! git remote get-url origin &> /dev/null; then
+    echo "[2/5] Adding remote origin..."
+    git remote add origin "https://steven_roc:${ACCESS_TOKEN}@git.zhonjin.com:40717/steven_roc/${REPO_NAME}.git"
 fi
 
-# Add all files
-echo "[3/4] Staging files..."
+# 添加所有文件
+echo "[3/5] Staging files..."
 git add -A
 
-# Check if there are changes to commit
+# 检查是否有变更
 if git diff --staged --quiet; then
     echo "No changes to commit"
 else
-    # Commit
-    echo "[4/4] Committing changes..."
-    git commit -m "Initial commit: Hikvision ISUP Client project"
-    echo "Changes committed"
+    # 提交
+    echo "[4/5] Committing changes..."
+    git commit -m "$(date '+%Y-%m-%d %H:%M:%S') - Auto sync update"
     
-    # Push to remote
-    echo "Pushing to remote..."
+    # 推送(注意: 不要使用 -o 参数,Gogs 可能不支持 push options)
+    echo "[5/5] Pushing to Gogs..."
     git push -u origin main
-    
-    echo ""
-    echo "=== Git setup complete ==="
-    echo "Repository: ${FULL_URL}"
-    echo ""
-    echo "Future sync commands:"
-    echo "  git add -A"
-    echo "  git commit -m 'Your commit message'"
-    echo "  git push"
-else
-    echo "Nothing to push"
 fi
 
 echo ""
-echo "=== Git setup complete ==="
+echo "=== Sync complete ==="
+echo "Repository: ${FULL_URL}"