فهرست منبع

git push 脚本

yichael 3 هفته پیش
والد
کامیت
7497730db8

+ 0 - 57
bat-tool/git-push.bat

@@ -1,57 +0,0 @@
-@echo off
-chcp 65001 >nul
-title Git Push
-
-cd /d "%~dp0\.."
-
-REM ========== Configure main branch name here ==========
-REM Leave empty to auto-detect (priority: master > main > current branch)
-set CONFIG_BRANCH=master
-REM ======================================================
-
-REM Detect main branch
-if "%CONFIG_BRANCH%"=="" (
-    REM Auto-detect main branch
-    git show-ref --verify --quiet refs/heads/master
-    if %errorlevel% == 0 (
-        set MAIN_BRANCH=master
-    ) else (
-        git show-ref --verify --quiet refs/heads/main
-        if %errorlevel% == 0 (
-            set MAIN_BRANCH=main
-        ) else (
-            REM If none found, use current branch
-            for /f "tokens=*" %%i in ('git rev-parse --abbrev-ref HEAD') do set MAIN_BRANCH=%%i
-        )
-    )
-) else (
-    REM Use configured branch
-    set MAIN_BRANCH=%CONFIG_BRANCH%
-)
-
-REM Show files to be pushed
-echo.
-echo Files to be pushed:
-echo ========================================
-git diff --name-status origin/%MAIN_BRANCH%..HEAD 2>nul
-if errorlevel 1 (
-    REM If remote branch doesn't exist, show all files
-    git log --name-status --oneline HEAD 2>nul | findstr /V "^[a-f0-9]"
-)
-echo ========================================
-echo.
-
-REM Push to main branch
-git push origin %MAIN_BRANCH%
-
-if errorlevel 1 (
-    echo.
-    echo [ERROR] Push failed
-    echo.
-    pause
-) else (
-    echo.
-    echo [OK] Push successful
-    echo.
-    pause
-)

+ 14 - 0
bat-tool/git/git-push/git-push.bat

@@ -0,0 +1,14 @@
+@echo off
+chcp 65001 >nul
+title Git Push
+cd /d "%~dp0"
+node git-push.js
+if errorlevel 1 (
+    echo.
+    pause
+    exit /b 1
+) else (
+    echo.
+    pause
+    exit /b 0
+)

+ 76 - 0
bat-tool/git/git-push/git-push.js

@@ -0,0 +1,76 @@
+#!/usr/bin/env node
+const { execSync } = require('child_process')
+const path = require('path')
+
+// Get project root (two levels up from this script)
+const projectRoot = path.resolve(__dirname, '../..')
+
+// Change to project root
+process.chdir(projectRoot)
+
+// Configuration: main branch name (leave empty to auto-detect)
+const CONFIG_BRANCH = 'master'
+
+// Detect main branch
+let mainBranch = CONFIG_BRANCH
+
+if (!CONFIG_BRANCH) {
+  // Auto-detect main branch (priority: master > main > current branch)
+  try {
+    execSync('git show-ref --verify --quiet refs/heads/master', { stdio: 'ignore' })
+    mainBranch = 'master'
+  } catch (e) {
+    try {
+      execSync('git show-ref --verify --quiet refs/heads/main', { stdio: 'ignore' })
+      mainBranch = 'main'
+    } catch (e2) {
+      // Use current branch
+      mainBranch = execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf-8' }).trim()
+    }
+  }
+}
+
+// Show files to be pushed
+console.log('')
+console.log('Files to be pushed:')
+console.log('========================================')
+try {
+  const diffOutput = execSync(`git diff --name-status origin/${mainBranch}..HEAD`, { encoding: 'utf-8', stdio: ['ignore', 'pipe', 'ignore'] })
+  console.log(diffOutput.trim())
+} catch (e) {
+  // If remote branch doesn't exist, show all files
+  try {
+    const logOutput = execSync('git log --name-status --oneline HEAD', { encoding: 'utf-8', stdio: ['ignore', 'pipe', 'ignore'] })
+    const lines = logOutput.split('\n').filter(line => line.trim() && !/^[a-f0-9]/.test(line))
+    console.log(lines.join('\n'))
+  } catch (e2) {
+    // Ignore errors
+  }
+}
+console.log('========================================')
+console.log('')
+
+// Push to main branch
+console.log('')
+console.log(`Pushing to origin/${mainBranch}...`)
+console.log('========================================')
+try {
+  const pushOutput = execSync(`git push origin ${mainBranch}`, { encoding: 'utf-8', stdio: 'inherit' })
+  console.log('========================================')
+  console.log('')
+  console.log('========================================')
+  console.log('[OK] Push successful')
+  console.log('========================================')
+  console.log('')
+  process.exit(0)
+} catch (error) {
+  console.log('========================================')
+  console.log('')
+  console.log('========================================')
+  console.log(`[ERROR] Push failed (exit code: ${error.status || 1})`)
+  console.log('========================================')
+  console.log('')
+  console.log('Please check the error messages above.')
+  console.log('')
+  process.exit(error.status || 1)
+}

+ 0 - 0
bat-tool/git-update-pwd/git-credential-config.bat → bat-tool/git/git-update-pwd/git-credential-config.bat


+ 0 - 0
bat-tool/git-update-pwd/git-credential-config.ps1 → bat-tool/git/git-update-pwd/git-credential-config.ps1