|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var callsheltask = (args) => { return () => { return nodeShellExec.apply(null, args) } } |
|
|
var callsheltask = (args) => { return () => { return nodeShellExec.apply(null, args) } } |
|
|
|
|
|
var callgitbashtask = (args) => { return () => { |
|
|
|
|
|
return nodeShellExec( `"${gitbash}"`, ['-c', `"${args[0]} ${args[1].join(' ')}"`], args[2]) } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var getTaskCheckExists = (command, options) => { |
|
|
var getTaskCheckExists = (command, options) => { |
|
|
options = options || {} |
|
|
options = options || {} |
|
|
|
|
|
|
|
|
// git branch --set-upstream-to=elixir-unc/master master |
|
|
// git branch --set-upstream-to=elixir-unc/master master |
|
|
// git push --set-upstream elixir-unc branch.. |
|
|
// git push --set-upstream elixir-unc branch.. |
|
|
, 'set-url': (remotename, url) => { |
|
|
, 'set-url': (remotename, url) => { |
|
|
|
|
|
// git remote set-url elixir-unc //10.10.5.60/gitrepo/chess/bbhverse |
|
|
var pushable = processedArgs.pushable || false; |
|
|
var pushable = processedArgs.pushable || false; |
|
|
remotename = remotename || processedArgs._[1] |
|
|
remotename = remotename || processedArgs._[1] |
|
|
url = url || processedArgs._[2] |
|
|
url = url || processedArgs._[2] |
|
|
|
|
|
|
|
|
if (pushable) { |
|
|
if (pushable) { |
|
|
return [ |
|
|
return [ |
|
|
['git', ['remote', 'set-url', remotename, url + '/' + repo], { cwd: instanceroot + '/' + repo }] |
|
|
['git', ['remote', 'set-url', remotename, url + '/' + repo], { cwd: instanceroot + '/' + repo }] |
|
|
|
|
|
, ['git', ['remote', `set-url`, '--push', remotename, url + '/' + repo], { cwd: instanceroot + '/' + repo }] |
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var x = (args) => { |
|
|
|
|
|
return () => { |
|
|
|
|
|
// console.log(args) |
|
|
|
|
|
return nodeShellExec.apply(null, args) |
|
|
|
|
|
} |
|
|
|
|
|
// return Promise.resolve(true) |
|
|
|
|
|
} |
|
|
var perform_git_seturl = (dir) => { |
|
|
var perform_git_seturl = (dir) => { |
|
|
op['is-git-repo'](dir).then((logEntry) => { |
|
|
op['is-git-repo'](dir).then((logEntry) => { |
|
|
any(serial_perform_git_seturl(dir.name).map(x)) |
|
|
any(serial_perform_git_seturl(dir.name).map(x)) |
|
|
|
|
|
|
|
|
var perform_git_remove = (dir) => { |
|
|
var perform_git_remove = (dir) => { |
|
|
op['is-git-repo'](dir).then((logEntry) => { |
|
|
op['is-git-repo'](dir).then((logEntry) => { |
|
|
// console.log(code) |
|
|
// console.log(code) |
|
|
// if (code) { |
|
|
|
|
|
|
|
|
if (logEntry.success) { |
|
|
nodeShellExec('git', ['remote', 'get-url', remotename], { cwd: dir.name, stdio: 'ignore' }).then(() => { |
|
|
nodeShellExec('git', ['remote', 'get-url', remotename], { cwd: dir.name, stdio: 'ignore' }).then(() => { |
|
|
any(serial_perform_git_remove(dir.name).map(x)) |
|
|
any(serial_perform_git_remove(dir.name).map(x)) |
|
|
}) |
|
|
}) |
|
|
.catch((e) => { |
|
|
.catch((e) => { |
|
|
console.log('skipped : ' + dir.name + ', reason : No remote named origin') |
|
|
console.log('skipped : ' + dir.name + ', reason : No remote named origin') |
|
|
}) |
|
|
}) |
|
|
// } |
|
|
|
|
|
|
|
|
} |
|
|
// else console.log('Skipped : Not a Git Repo : ' + dir.name) |
|
|
// else console.log('Skipped : Not a Git Repo : ' + dir.name) |
|
|
}).catch((e) => { |
|
|
}).catch((e) => { |
|
|
console.log('Failed : ' + dir.name) |
|
|
|
|
|
|
|
|
// console.log('Failed : ' + dir.name) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else return op['runas']() |
|
|
else return op['runas']() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
, 'repo-relocate' : function(args){ |
|
|
|
|
|
// relocate a subfolder in source repo to same subfolder in target repo with history. |
|
|
|
|
|
|
|
|
|
|
|
var args = args || { |
|
|
|
|
|
remotebase : processedArgs._[4] || 'http://git.bbh/chess/' |
|
|
|
|
|
, folder : processedArgs._[3] || 'server' |
|
|
|
|
|
, sourcerepo : processedArgs._[2] || 'client' |
|
|
|
|
|
, targetrepo : processedArgs._[1] || 'elixir-server' |
|
|
|
|
|
} |
|
|
|
|
|
var sourcerepooptions = { cwd: `${instanceroot}/relocate/${args.sourcerepo}` |
|
|
|
|
|
// , stdio: ['pipe', process.stdout, process.stderr] |
|
|
|
|
|
, inherit: true, |
|
|
|
|
|
shell: true, |
|
|
|
|
|
env: process.env |
|
|
|
|
|
, runas: processedArgs.runas |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return op['repo-split'](args).then(()=>{ |
|
|
|
|
|
return op['repo-merge'](args).then(()=>{ |
|
|
|
|
|
|
|
|
|
|
|
// cleanup folder from source. |
|
|
|
|
|
var cmdseq = [ |
|
|
|
|
|
['rm', ['-rf', `${args.folder}`], sourcerepooptions ] |
|
|
|
|
|
// commits have to intentional... |
|
|
|
|
|
// , ['git', ['commit', '-a', '-m', `relocate folder ${args.folder} to ${targetrepo}`], sourcerepooptions ] |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
return any(cmdseq.map(callsheltask)) |
|
|
|
|
|
}) |
|
|
|
|
|
}).catch(e=>{console.error(e)}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
, 'repo-split' : function(args) { |
|
|
|
|
|
|
|
|
|
|
|
// https://gist.github.com/smdabdoub/17065c348289158277b5 |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Eg : folder, remotebase, sourcerepo, targetrepo |
|
|
|
|
|
* args.folder = 'server' |
|
|
|
|
|
* args.remotebase = 'https://git.bbh/chess/' |
|
|
|
|
|
* args.sourcerepo = 'client' |
|
|
|
|
|
* args.targetrepo = 'elixir-server' |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
var args = args || { |
|
|
|
|
|
folder : 'server' |
|
|
|
|
|
, remotebase : 'http://git.bbh/chess/' |
|
|
|
|
|
, sourcerepo : 'client' |
|
|
|
|
|
, targetrepo : 'elixir-server' |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var options = { cwd: `${instanceroot}/relocate` |
|
|
|
|
|
// , stdio: ['pipe', process.stdout, process.stderr] |
|
|
|
|
|
, inherit: true, |
|
|
|
|
|
shell: true, |
|
|
|
|
|
env: process.env |
|
|
|
|
|
, runas: processedArgs.runas |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var cmdseq = [ |
|
|
|
|
|
// create a temporary working dir in current folder where we started execution. |
|
|
|
|
|
['mkdir', [ '-p', 'relocate']] |
|
|
|
|
|
, ['git', ['clone', `${args.remotebase}${args.sourcerepo}`], options ] |
|
|
|
|
|
, ['git', ['clone', `${args.sourcerepo}`, `relocate-${args.sourcerepo}-${args.folder}`], options] |
|
|
|
|
|
, ['git', ['clone', `${args.remotebase}${args.targetrepo}`, `relocate-${args.targetrepo}-${args.folder}`], options] |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
return any(cmdseq.map(callsheltask)).then(() => { |
|
|
|
|
|
// , ['git', ['subtree', 'split', '-P', `${args.folder}`, '-b', `relocate-${args.sourcerepo}-${args.folder}`], sourcerepooptions] |
|
|
|
|
|
// split doesnt retain folder structure we need to move and commit ourselves through a branch to retain history... |
|
|
|
|
|
// , ['git', [`checkout relocate-${args.sourcerepo}-${args.folder}`], sourcerepooptions] |
|
|
|
|
|
// , ['mkdir', [`${args.folder}`], sourcerepooptions] |
|
|
|
|
|
// , ['git', ['mv', `!(${args.folder})`, `${args.folder}`], sourcerepooptions ] // requires shopt -s extglob |
|
|
|
|
|
// , ['git', ['commit', `-m`, 'Moved to same subfolder after subtree split in branch'] , sourcerepooptions] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// subtree split and filter-branch are options. We currently use repo-filter. |
|
|
|
|
|
return op['filter-repo'](args) |
|
|
|
|
|
}).catch(e=>{console.error(e); throw 'failed'}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
, 'repo-merge' : function(args) { |
|
|
|
|
|
// Merge source repo into target repo |
|
|
|
|
|
var args = args || { |
|
|
|
|
|
folder : 'server' |
|
|
|
|
|
, remotebase : 'http://git.bbh/chess/' |
|
|
|
|
|
, sourcerepo : 'client' |
|
|
|
|
|
, targetrepo : 'elixir-server' |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var sourcerepooptions = { cwd: `${instanceroot}/relocate/relocate-${args.sourcerepo}-${args.folder}` |
|
|
|
|
|
// , stdio: ['pipe', process.stdout, process.stderr] |
|
|
|
|
|
, inherit: true, |
|
|
|
|
|
shell: true, |
|
|
|
|
|
env: process.env |
|
|
|
|
|
, runas: processedArgs.runas |
|
|
|
|
|
} |
|
|
|
|
|
var targetrepooptions = { cwd: `${instanceroot}/relocate/relocate-${args.targetrepo}-${args.folder}` |
|
|
|
|
|
// , stdio: ['pipe', process.stdout, process.stderr] |
|
|
|
|
|
, inherit: true, |
|
|
|
|
|
shell: true, |
|
|
|
|
|
env: process.env |
|
|
|
|
|
, runas: processedArgs.runas |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var cmdseq = [ |
|
|
|
|
|
['git', ['pull', `../relocate-${args.sourcerepo}-${args.folder}`, `master`, '--allow-unrelated-histories'] |
|
|
|
|
|
, targetrepooptions ] |
|
|
|
|
|
// , ['git', ['push', targetrepooptions ] // manual push for now.. |
|
|
|
|
|
] |
|
|
|
|
|
return any(cmdseq.map(callsheltask)).catch(e=>{console.error(e)}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
, 'filter-repo' : function(args){ |
|
|
|
|
|
// Merge source repo into target repo |
|
|
|
|
|
var args = args || { |
|
|
|
|
|
folder : 'server' |
|
|
|
|
|
, remotebase : 'http://git.bbh/chess/' |
|
|
|
|
|
, targetrepo : 'elixir-server' |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var targetrepooptions = { cwd: `${instanceroot}/relocate/relocate-${args.sourcerepo}-${args.folder}` |
|
|
|
|
|
, inherit: true, shell: true |
|
|
|
|
|
, env: process.env |
|
|
|
|
|
, runas: processedArgs.runas |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var cmdseq = [ |
|
|
|
|
|
// git checkout -b feature/merge-old-project |
|
|
|
|
|
// git remote add src-project ../src-project |
|
|
|
|
|
['git', ['filter-repo', '--path', `${args.folder}`], targetrepooptions ] |
|
|
|
|
|
] |
|
|
|
|
|
return any(cmdseq.map(callsheltask)).catch(e=>{console.error(e); throw 'failed' }) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
, 'filter-branch' : function(preservefolder, repo){ |
|
|
|
|
|
// https://stackoverflow.com/questions/359424/detach-move-subdirectory-into-separate-git-repository |
|
|
|
|
|
// git subtree split -P <name-of-folder> -b <name-of-new-branch> |
|
|
|
|
|
// Preserve a specific folder. |
|
|
|
|
|
// PB : TODO -- filter-branch has known issues. Explore subtree and filter-repo... |
|
|
|
|
|
/* |
|
|
|
|
|
git clone repo reposplit |
|
|
|
|
|
git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter {{folder}} -- --all |
|
|
|
|
|
git remote rm origin |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
throw 'filter-repo-history not yet implmented pls refer to manual commands in code.' |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// , 'repo-merge-folder' : function(mergetarget, mergesource, mergefolder){ |
|
|
|
|
|
// // Merge repo2 into a subfolder in repo1 |
|
|
|
|
|
// // https://alexharv074.github.io/puppet/2017/10/04/merge-a-git-repository-and-its-history-into-a-subdirectory-of-a-second-git-repository.html |
|
|
|
|
|
// // https://thoughts.t37.net/merging-2-different-git-repositories-without-losing-your-history-de7a06bba804 |
|
|
|
|
|
// /* |
|
|
|
|
|
// cd repo1 |
|
|
|
|
|
// git remote add -f tempmergesource ../{{mergesource}}/.git |
|
|
|
|
|
// git merge -s ours --no-commit tempmergesource/master --allow-unrelated-histories |
|
|
|
|
|
// git read-tree --prefix={{mergefolder}} -u tempmergesource/master: |
|
|
|
|
|
// git commit |
|
|
|
|
|
|
|
|
|
|
|
// // Repair History |
|
|
|
|
|
// // === git filter-branch --tree-filter '(echo === $GIT_COMMIT:; git ls-tree $GIT_COMMIT) >> /tmp/tree.log' |
|
|
|
|
|
|
|
|
|
|
|
// #!/usr/bin/env bash |
|
|
|
|
|
|
|
|
|
|
|
// first=ed4f16becc2f03820c164e0617bb98f12ff49ef0 |
|
|
|
|
|
// last=038e26e21bd60fa265d6637261f3bc918780d2e8 |
|
|
|
|
|
// subdir=server |
|
|
|
|
|
|
|
|
|
|
|
// git filter-branch --tree-filter ' |
|
|
|
|
|
// first='"$first"' |
|
|
|
|
|
// last='"$last"' |
|
|
|
|
|
|
|
|
|
|
|
// subdir='"$subdir"' |
|
|
|
|
|
// log_file=/tmp/filter.log |
|
|
|
|
|
|
|
|
|
|
|
// [ "$GIT_COMMIT" = "$first" ] && seen_first=true |
|
|
|
|
|
|
|
|
|
|
|
// if [ "$seen_first" = "true" ] && [ "$seen_last" != "true" ]; then |
|
|
|
|
|
// echo "=== $GIT_COMMIT: making changes" |
|
|
|
|
|
// files=$(git ls-tree --name-only $GIT_COMMIT) |
|
|
|
|
|
// mkdir -p $subdir |
|
|
|
|
|
// for i in $files; do |
|
|
|
|
|
// mv $i $subdir || echo "ERR: mv $i $subdir failed" |
|
|
|
|
|
// done |
|
|
|
|
|
// else |
|
|
|
|
|
// echo "=== $GIT_COMMIT: ignoring" |
|
|
|
|
|
// fi \ |
|
|
|
|
|
// >> $log_file |
|
|
|
|
|
|
|
|
|
|
|
// [ "$GIT_COMMIT" = "$last" ] && seen_last=true |
|
|
|
|
|
|
|
|
|
|
|
// status=0 # tell tree-filter never to fail |
|
|
|
|
|
// ' |
|
|
|
|
|
|
|
|
|
|
|
// git remote rm tempmergesource |
|
|
|
|
|
// */ |
|
|
|
|
|
// // better alternative for history |
|
|
|
|
|
// /** |
|
|
|
|
|
// * |
|
|
|
|
|
// git clone git@server.com:old-project.git |
|
|
|
|
|
// git clone git@server.com:new-project.git |
|
|
|
|
|
|
|
|
|
|
|
// cd old-project |
|
|
|
|
|
// mkdir old-project |
|
|
|
|
|
// git mv !(old-project) old-project |
|
|
|
|
|
// ls -la and gt mv hidden files .... |
|
|
|
|
|
// git commit -a -S -m “Moving old project into its own subdirectory” |
|
|
|
|
|
|
|
|
|
|
|
// cd ../new-project |
|
|
|
|
|
// git remote add old-project ../old-project |
|
|
|
|
|
// git fetch old-project |
|
|
|
|
|
// git checkout -b feature/merge-old-project |
|
|
|
|
|
// git merge -S --allow-unrelated-histories old-project/master |
|
|
|
|
|
// git push origin feature/merge-old-project |
|
|
|
|
|
// git remote rm old-project |
|
|
|
|
|
// */ |
|
|
|
|
|
|
|
|
|
|
|
// throw 'merge-repos not yet implmented pls refer to manual commands in code.' |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
, 'pull' : (label) => { |
|
|
, 'pull' : (label) => { |
|
|
// Usage : |
|
|
// Usage : |
|
|
// elxr pull -- Defaults to run config |
|
|
// elxr pull -- Defaults to run config |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var performCloneAndCheckout = null; |
|
|
var performCloneAndCheckout = null; |
|
|
// cant use git checkout -b it fails when branch already exists. |
|
|
// cant use git checkout -b it fails when branch already exists. |
|
|
var performCheckout = performCloneAndCheckout = (def) => { |
|
|
|
|
|
if (excludeCheckouts[def.repo]) return Promise.resolve({ 'skipped': true }) |
|
|
|
|
|
|
|
|
var performCheckout = performCloneAndCheckout = (def) => {if (excludeCheckouts[def.repo]) return Promise.resolve({ 'skipped': true }) |
|
|
|
|
|
|
|
|
return performPullOrCloneForBranch(def).then(()=>{ |
|
|
return performPullOrCloneForBranch(def).then(()=>{ |
|
|
nodeShellExec('git', ['checkout', def.branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { |
|
|
nodeShellExec('git', ['checkout', def.branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var g = { |
|
|
var g = { |
|
|
'client': () => { |
|
|
'client': () => { |
|
|
|
|
|
// ember new --skip-bower --no-welcome --skip-git -b {{blueprint}} |
|
|
|
|
|
|
|
|
console.info('Creating new ember client named : ' + processedArgs._[2]); |
|
|
console.info('Creating new ember client named : ' + processedArgs._[2]); |
|
|
var step1 = nodeShellExec('cmd', ['/c', 'ember', 'new', processedArgs._[2]], { |
|
|
var step1 = nodeShellExec('cmd', ['/c', 'ember', 'new', processedArgs._[2]], { |
|
|
stdio: ['pipe', process.stdout, process.stderr], |
|
|
stdio: ['pipe', process.stdout, process.stderr], |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var util = require('util') |
|
|
|
|
|
|
|
|
var util = require('util'); |
|
|
var cliname = 'elxr'; |
|
|
var cliname = 'elxr'; |
|
|
var ver = '1.1'; |
|
|
var ver = '1.1'; |
|
|
var help = `# list of commands... please refer dveloper documentation for ${cliname} |
|
|
var help = `# list of commands... please refer dveloper documentation for ${cliname} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var noprerequisites = { |
|
|
var noprerequisites = { |
|
|
add : true |
|
|
|
|
|
|
|
|
add : true, 'set-url' : true, 'repo-relocate' : true |
|
|
} |
|
|
} |
|
|
var skipprereqs = {} |
|
|
var skipprereqs = {} |
|
|
var maintask = () => { |
|
|
var maintask = () => { |
|
|
|
|
|
|
|
|
var min = runtimestamp; |
|
|
var min = runtimestamp; |
|
|
var collect = [] |
|
|
var collect = [] |
|
|
|
|
|
|
|
|
|
|
|
if(noprerequisites[processedArgs._[0]] |
|
|
|
|
|
|| skipprereqs[processedArgs._[0]] |
|
|
|
|
|
) { |
|
|
|
|
|
return op[processedArgs._[0]]() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return detectInstance().then((detectedInstance)=>{ |
|
|
return detectInstance().then((detectedInstance)=>{ |
|
|
|
|
|
|