Initial commit
This commit is contained in:
+20
-40
@@ -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('=== 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('=== 设置用户信息 ===')
|
||||
await git.addConfig('user.name', 'jiapengyu')
|
||||
await git.addConfig('user.email', 'jiapengyu@example.com')
|
||||
console.log('=== Add all files ===');
|
||||
execSync(`${gitPath} add .`, { stdio: 'inherit', cwd: __dirname });
|
||||
|
||||
console.log('=== 设置远程仓库 ===')
|
||||
const remoteUrl = 'git@git.torchcloud.cn:jiapengyu/huishou.git'
|
||||
await git.addRemote('origin', remoteUrl)
|
||||
console.log('=== Commit code ===');
|
||||
execSync(`${gitPath} commit -m "Initial commit"`, { stdio: 'inherit', cwd: __dirname });
|
||||
|
||||
console.log('=== 添加所有文件 ===')
|
||||
await git.add('.')
|
||||
console.log('=== Add remote ===');
|
||||
execSync(`${gitPath} remote add origin git@git.torchcloud.cn:jiapengyu/huishou.git`, { stdio: 'inherit', cwd: __dirname });
|
||||
|
||||
console.log('=== 提交代码 ===')
|
||||
await git.commit('Initial commit - huishou project')
|
||||
console.log('=== Push to remote ===');
|
||||
execSync(`${gitPath} push -u origin master`, { stdio: 'inherit', cwd: __dirname });
|
||||
|
||||
console.log('=== 推送代码 ===')
|
||||
await git.push('origin', 'main', { '--set-upstream': null })
|
||||
|
||||
console.log('=== 推送成功 ===')
|
||||
console.log('=== Success ===');
|
||||
} 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)
|
||||
console.error('=== Failed ===');
|
||||
console.error(error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user