diff --git a/git-push.js b/git-push.js index 44dda1f2..b4b5150a 100644 --- a/git-push.js +++ b/git-push.js @@ -1,50 +1,30 @@ -const simpleGit = require('simple-git') -const path = require('path') +const { execSync } = require('child_process'); +const fs = require('fs'); -const git = simpleGit(path.join(__dirname)) +const gitPath = 'D:\\Git\\bin\\git.exe'; -const run = async () => { - try { - console.log('=== 初始化Git仓库 ===') - await git.init() - - console.log('=== 设置用户信息 ===') - await git.addConfig('user.name', 'jiapengyu') - await git.addConfig('user.email', 'jiapengyu@example.com') - - console.log('=== 设置远程仓库 ===') - const remoteUrl = 'git@git.torchcloud.cn:jiapengyu/huishou.git' - await git.addRemote('origin', remoteUrl) - - console.log('=== 添加所有文件 ===') - await git.add('.') - - console.log('=== 提交代码 ===') - await git.commit('Initial commit - huishou project') - - console.log('=== 推送代码 ===') - await git.push('origin', 'main', { '--set-upstream': null }) - - console.log('=== 推送成功 ===') - } catch (error) { - console.error('=== 推送失败 ===') - console.error(error.message) - - // 如果main分支不存在,尝试创建 - if (error.message.includes('fatal: A branch named')) { - try { - console.log('=== 创建main分支 ===') - await git.checkoutLocalBranch('main') - await git.add('.') - await git.commit('Initial commit - huishou project') - await git.push('origin', 'main', { '--set-upstream': null }) - console.log('=== 推送成功 ===') - } catch (err) { - console.error('=== 仍然失败 ===') - console.error(err.message) - } - } +try { + console.log('=== Remove lock file ==='); + const lockFile = 'D:\\Trae\\huishou\\.git\\index.lock'; + if (fs.existsSync(lockFile)) { + fs.unlinkSync(lockFile); + console.log('Lock file removed'); } + + console.log('=== Add all files ==='); + execSync(`${gitPath} add .`, { stdio: 'inherit', cwd: __dirname }); + + console.log('=== Commit code ==='); + execSync(`${gitPath} commit -m "Initial commit"`, { stdio: 'inherit', cwd: __dirname }); + + console.log('=== Add remote ==='); + execSync(`${gitPath} remote add origin git@git.torchcloud.cn:jiapengyu/huishou.git`, { stdio: 'inherit', cwd: __dirname }); + + console.log('=== Push to remote ==='); + execSync(`${gitPath} push -u origin master`, { stdio: 'inherit', cwd: __dirname }); + + console.log('=== Success ==='); +} catch (error) { + console.error('=== Failed ==='); + console.error(error.message); } - -run() diff --git a/push-git.bat b/push-git.bat new file mode 100644 index 00000000..e6fa3384 --- /dev/null +++ b/push-git.bat @@ -0,0 +1,4 @@ +@echo off +D:\Git\bin\git.exe commit -m "Initial commit" +D:\Git\bin\git.exe remote add origin git@git.torchcloud.cn:jiapengyu/huishou.git +D:\Git\bin\git.exe push -u origin master