const { execSync } = require('child_process'); const fs = require('fs'); const gitPath = 'D:\\Git\\bin\\git.exe'; try { console.log('=== Remove index.lock ==='); const lockFile = '.git/index.lock'; if (fs.existsSync(lockFile)) { fs.unlinkSync(lockFile); console.log('Removed index.lock'); } console.log('=== Add all files ==='); execSync(`${gitPath} add --all`, { stdio: 'inherit', cwd: __dirname }); console.log('=== Check git status ==='); execSync(`${gitPath} status`, { stdio: 'inherit', cwd: __dirname }); console.log('=== Commit all files ==='); execSync(`${gitPath} commit -m "Initial commit - full huishou project"`, { stdio: 'inherit', cwd: __dirname }); console.log('=== Add remote ==='); try { execSync(`${gitPath} remote add origin git@git.torchcloud.cn:jiapengyu/huishou.git`, { stdio: 'inherit', cwd: __dirname }); } catch (e) { console.log('Remote origin already exists, updating...'); execSync(`${gitPath} remote set-url origin git@git.torchcloud.cn:jiapengyu/huishou.git`, { stdio: 'inherit', cwd: __dirname }); } console.log('=== Push with force ==='); const env = { ...process.env }; env.GIT_SSH_COMMAND = 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'; execSync(`${gitPath} push -f origin master`, { stdio: 'inherit', cwd: __dirname, env: env }); console.log('=== Success ==='); } catch (error) { console.error('=== Failed ==='); console.error('Exit code:', error.status); console.error(error.message); }