mirror of
https://github.com/OBKoro1/autoCommit.git
synced 2024-11-22 10:29:23 +08:00
修复window系统下进入其他磁盘报错的问题
This commit is contained in:
parent
9937a5d5b7
commit
6a40dd776f
@ -1,13 +1,3 @@
|
|||||||
/*
|
|
||||||
* Author : OBKoro1
|
|
||||||
* Date : 2019-12-30 16:59:30
|
|
||||||
* @LastEditors : OBKoro1
|
|
||||||
* @LastEditTime : 2020-01-15 11:46:52
|
|
||||||
* FilePath : /autoCommit/src/models/commitHandle.ts
|
|
||||||
* Description : commit 具体操作
|
|
||||||
* https://github.com/OBKoro1
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { webviewMsg } from '../util/dataStatement';
|
import { webviewMsg } from '../util/dataStatement';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
@ -40,7 +30,6 @@ class CommitHandle {
|
|||||||
constructor(message: webviewMsg) {
|
constructor(message: webviewMsg) {
|
||||||
this.paramsObj = message.data;
|
this.paramsObj = message.data;
|
||||||
this.timeArr = [];
|
this.timeArr = [];
|
||||||
console.log('seb',sep)
|
|
||||||
this.timeHandle();
|
this.timeHandle();
|
||||||
this.autoCommitView = getPanelWebview();
|
this.autoCommitView = getPanelWebview();
|
||||||
this.userCancel = false;
|
this.userCancel = false;
|
||||||
@ -114,10 +103,10 @@ class CommitHandle {
|
|||||||
try {
|
try {
|
||||||
// 异步执行命令 让出线程 打印日志 等
|
// 异步执行命令 让出线程 打印日志 等
|
||||||
commitMsg = await new Promise((resolve, reject) => {
|
commitMsg = await new Promise((resolve, reject) => {
|
||||||
let cmd = `cd ${this.paramsObj.itemSrc} && git add . && git commit -m '${this.paramsObj.commitMsg}' --date='${time}'`;
|
const cmd = `git add . && git commit -m '${this.paramsObj.commitMsg}' --date='${time}'`;
|
||||||
exec(cmd, {
|
exec(cmd, {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
// cwd: this.paramsObj.itemSrc,
|
cwd: this.paramsObj.itemSrc,
|
||||||
env: undefined
|
env: undefined
|
||||||
},(error, stdout, stderr) => {
|
},(error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -170,10 +159,10 @@ class CommitHandle {
|
|||||||
outputLog('提交中...');
|
outputLog('提交中...');
|
||||||
this.autoCommitView.postMessage('提交中...', '提交中');
|
this.autoCommitView.postMessage('提交中...', '提交中');
|
||||||
const res = await new Promise((resolve, reject) => {
|
const res = await new Promise((resolve, reject) => {
|
||||||
let cmd = `cd ${this.paramsObj.itemSrc} && git pull && git push`;
|
const cmd = `git pull && git push`;
|
||||||
exec(cmd,{
|
exec(cmd,{
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
// cwd: this.paramsObj.itemSrc,
|
cwd: this.paramsObj.itemSrc,
|
||||||
env: undefined
|
env: undefined
|
||||||
},(error, stdout, stderr) => {
|
},(error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -196,8 +185,11 @@ class CommitHandle {
|
|||||||
this.autoCommitView.postMessage('回滚', '回滚');
|
this.autoCommitView.postMessage('回滚', '回滚');
|
||||||
outputLog('回滚中...');
|
outputLog('回滚中...');
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
let cmd = `cd ${this.paramsObj.itemSrc} && git reset --hard HEAD~${totalNum}`;
|
const cmd = `git reset --hard HEAD~${totalNum}`;
|
||||||
exec(cmd, (error, stdout, stderr) => {
|
exec(cmd,{
|
||||||
|
encoding: 'utf8',
|
||||||
|
cwd: this.paramsObj.itemSrc,
|
||||||
|
}, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
outputLog(`执行命令出错:${cmd}`);
|
outputLog(`执行命令出错:${cmd}`);
|
||||||
outputLog(`回滚失败:${error}`, stderr);
|
outputLog(`回滚失败:${error}`, stderr);
|
||||||
@ -292,22 +284,6 @@ class CommitHandle {
|
|||||||
}
|
}
|
||||||
return timeArr;
|
return timeArr;
|
||||||
}
|
}
|
||||||
// 同步执行命令
|
|
||||||
myExecSync(cmd: string) {
|
|
||||||
// 除了该方法直到子进程完全关闭后才返回 执行完毕 返回
|
|
||||||
try {
|
|
||||||
const res = execSync(cmd, {
|
|
||||||
encoding: 'utf8',
|
|
||||||
cwd: undefined,
|
|
||||||
env: undefined
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
} catch (err) {
|
|
||||||
outputLog(`执行命令出错:${cmd}`);
|
|
||||||
outputLog(`错误信息:${err}`);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CommitHandle;
|
export default CommitHandle;
|
||||||
|
Loading…
Reference in New Issue
Block a user