Ver código fonte

Fixed multiple performpulls and logging

production
pb 3 anos atrás
pai
commit
244e9e603b
1 arquivos alterados com 49 adições e 94 exclusões
  1. 49
    94
      index.js

+ 49
- 94
index.js Ver arquivo

@@ -32,12 +32,18 @@ var globSync = require('glob').sync;
var path = require('path');
const { isMaster } = require('cluster');

var getCmd = (command, args, options)=>{
return [command, args, Object.assign({
inherit : true, shell: true, title : `${command} `
}, options)
]
}

var getPullCmd = (repo)=>{
// console.log(useGitPull)

var pullCmd = [ gitInstallDir
, ['-c', 'for i in `git remote`; do git pull $i master; done;']
, ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;']
, { cwd : repo, title : 'pull all origins for ' + repo }]
// var pullCmd = ['pullall', [], { cwd : repo }]
if(useGitPull) pullCmd = ['git', ['pull'], {
@@ -50,21 +56,23 @@ var getPullCmd = (repo)=>{
return pullCmd
}

var getCmd = (command, args, options)=>{
return [command, args, Object.assign({
inherit : true, shell: true, title : `${command} `
}, options)
]
}

var performPull = (repo) => {

if(exludeMergeRepos[repo]) return Promise.resolve({ 'skipped' : true })


var performPull = (repo) => {
if(existsSync(repo)) {
console.log('pulling ' + repo)
return nodeShellExec.apply(null, getPullCmd(repo)).catch((e)=>{ console.error(e) })
return nodeShellExec.apply(null, getPullCmd(repo)).then(()=>{
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success:true}), {'flag':'a+'} )
}
else statuslog.statuslog(null, repo)
return true;
})
.catch((e)=>{
e.repo = repo;
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), {'flag':'a+'} )
}
else statuslog.statuslog(e); console.error(e)
})
}
else {
console.log('cloning ' + repo)
@@ -74,7 +82,9 @@ var performPull = (repo) => {
inherit : true, shell: true,
env: process.env
, runas : processedArgs.runas
}).catch((e)=>{ console.error(e) }).then(()=>{
}).catch((e)=>{
throw e;
}).then(()=>{

return nodeShellExec('git', ['config', '--replace-all' , 'core.symlinks', true],
{
@@ -84,6 +94,26 @@ var performPull = (repo) => {
, runas : processedArgs.runas
, title : `git core.symlinks --replace-all true for ${defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'}`
})
.then(()=>{
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success:true}), {'flag':'a+'} )
}
else statuslog.statuslog(null, repo)
})
.catch((e)=>{
e.repo = repo;
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), {'flag':'a+'} )
}
else statuslog.statuslog(e);
})
})
.catch(e=>{
e.repo = repo;
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), {'flag':'a+'} )
}
else statuslog.statuslog(e);
})
}
}
@@ -319,7 +349,7 @@ var op = {
var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self');
args.push('--nodepath='+r[r.length-1])
args.push('--node_env='+env.NODE_ENV)
if(_.debug) args.push('--debug=true') // Enable to debug elevated..
if(processedArgs.debug) args.push('--debug=true') // Enable to debug elevated..

return nodeShellExec('MSHTA', [`"${args.join('" "')}"`]
, {
@@ -638,83 +668,6 @@ var op = {
console.log('Running exlr pull : ' + path.dirname(__dirname))

var useGitPull = processedArgs.useGitPull || false;
var getPullCmd = (repo)=>{
// console.log(useGitPull)

var pullCmd = [ gitInstallDir
, ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;']
, { cwd : repo, title : 'pull all origins for ' + repo }]
// var pullCmd = ['pullall', [], { cwd : repo }]
if(useGitPull) pullCmd = ['git', ['pull'], {
inherit : true, shell: true,
cwd : repo
// , env: process.env
, runas : processedArgs.runas
, title : `git pull ${repo}`
}]
return pullCmd
}

var performPull = (repo) => {
if(existsSync(repo)) {
console.log('pulling ' + repo)
return nodeShellExec.apply(null, getPullCmd(repo)).then(()=>{
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success:true}), {'flag':'a+'} )
}
else statuslog.statuslog(null, repo)
return true;
})
.catch((e)=>{
e.repo = repo;
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), {'flag':'a+'} )
}
else statuslog.statuslog(e); console.error(e)
})
}
else {
// PB : TODO -- detect if a clonable repo exists in currentGitAuthUser
return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'],
{
inherit : true, shell: true,
env: process.env
, runas : processedArgs.runas
}).catch((e)=>{
throw e;
}).then(()=>{

return nodeShellExec('git', ['config', '--replace-all' , 'core.symlinks', true],
{
inherit : true, shell: true,
env: process.env
, cwd : repo
, runas : processedArgs.runas
, title : `git core.symlinks --replace-all true for ${defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'}`
})
.then(()=>{
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success:true}), {'flag':'a+'} )
}
else statuslog.statuslog(null, repo)
})
.catch((e)=>{
e.repo = repo;
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), {'flag':'a+'} )
}
else statuslog.statuslog(e);
})
})
.catch(e=>{
e.repo = repo;
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), {'flag':'a+'} )
}
else statuslog.statuslog(e);
})
}
}

if(__isElevated){
return any(elevatedRunasRepos.map((repo)=>performPull(repo))).then(()=>{
@@ -727,7 +680,9 @@ var op = {
else {
// PB : TODO -- Rename op['runas'] to 'elevate'
return op['runas']().then(()=>{ return true; })
.catch(()=>{})
.catch((e)=>{
console.error(e)
})
.finally(()=>{
if(!processedArgs.runas) {
var pendingpulls = [];

Carregando…
Cancelar
Salvar