Przeglądaj źródła

refresh remotes

master
chess 3 lat temu
rodzic
commit
9329be25f3
2 zmienionych plików z 102 dodań i 15 usunięć
  1. 96
    9
      index.js
  2. 6
    6
      repo-manifest.js

+ 96
- 9
index.js Wyświetl plik

@@ -172,6 +172,15 @@ var getPullCmd = (repo, branch) => {
// console.log(useGitPull)var getPullCmd = (repo, branch) => {
// console.log(useGitPull)

var pullCmd = []
if(!branch) {
// console.warn('No branch was specified detecting from working client.')
// First check if working client exits.
// if (existsSync(instanceroot + '/' + repo)) {
pullCmd= gitops.getdiscoverbranchcmd(repo)
// }
// else performpull
}
// var pullCmd = [gitInstallDir
// , ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;']
// , { cwd: instanceroot + '/' + repo, title: 'pull all origins for ' + repo }]
@@ -181,14 +190,6 @@ var getPullCmd = (repo, branch) => {
, ['-c', 'for i in `git remote`; do git pull $i ' + branch + '; done;']
, { cwd: instanceroot + '/' + repo, title : 'pull all origins for ' + branch + ' ' + repo + ' ' + parameters.join(' ') }]
}
else {
// console.warn('No branch was specified detecting from working client.')
// First check if working client exits.
// if (existsSync(instanceroot + '/' + repo)) {
var pullCmd = gitops.getdiscoverbranchcmd(repo)
// }
// else performpull
}
// var pullCmd = ['pullall', [], { cwd : repo }]
if (useGitPull) pullCmd = ['git', ['pull'], {
inherit: true, shell: true,
@@ -667,6 +668,61 @@ var op = {
, 'reset' : ()=>{
// Reset the whole installation pertaining to this elxr folder.
}

, 'remote exists': (args) => {
var __args = {
remotename : args.remotename|| processedArgs._[2]
, url : args.url || processedArgs._[3]
, branch : args.branch || processedArgs._[4]
}

var command = ['git', ['remote', '-v']]
return nodeShellExec.apply(null, command).then(result=>{
return result.messages.find( (r)=> { return r.includes( __args.remotename ) })
})
}

, 'remote refresh': (args) => {
var __args = {
remotename : args.remotename|| processedArgs._[2]
, url : args.url || processedArgs._[3]
, branch : args.branch || processedArgs._[4]
}

// use the repo manifest to create missing remotes.
function perform_remote_refresh(dir){

var repo = dir.name
var dscoverbranchcmd = gitops.getdiscoverbranchcmd(repo)
var remotes = require(`${dir.name}/repo-manifest.js`)( null, { repouser : selectedinstance.repouser }).remotes;

return nodeShellExec.apply(null, dscoverbranchcmd(repo)).then(__branch=>{
var branch = __branch
var promises = []

remotes.foreach(remote =>{
Object.keys(remote).forEach(remotename => {
promises.push( op['remote exists'].then( exists => {
if(!exits) {
return op['remote add']( { remotename,
// PB : TODO -- use the most accessible remote instead of the first available.
url : (utils.js.isArray(remote[remotename]) ? remote[remotename][0] : remote[remotename]), branch
} )
}
})
)
})
})

return Promise.all(promises)
})
.catch((e) => { console.error(e); return { error: true, message: repo } })
}
dirs(perform_remote_refresh)

}
, 'remote add': (args) => {
// PB : TODO -- set-upstream-to should be chosen and intentionally switched. Coz we can have multiple upstream remotes.
@@ -905,7 +961,7 @@ var op = {
var cmdseq = [
// create a temporary working dir in current folder where we started execution.
['mkdir', [ '-p', 'relocate']]
['mkdir', [ '-p', `${instanceroot}/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]
@@ -1756,6 +1812,36 @@ var elxr = {
// Or an object with many repos and elevated repos
// Or a single repo ( Either Elevated or normal. )

// USAGE
// elxr pull elixir origin master
// elxr pull

// not all remote branches are setup to be tracked locally (respective remotes and branches).
// pull --all is useless. As it fetches all remotes and branches but only merges current branch.
// apart from remote tracking branches We are interested in pulling from all remotes and relavant branches.
// The branch pipline should feed back to master
// master -> test -> stage -> release[nnnn] -> production
// (master) <= git merge [all remotes] production && git merge [all remotes] release[nnnn]
// git merge [all remotes] stage && git merge [all remotes] test && git merge [all remotes] master

var __args = {
remotename : args.remotename|| processedArgs._[2]
, url : args.url || processedArgs._[3]
, branch : args.branch || processedArgs._[4] // If branch not specified opearte on the current branch of each working directorys
}

// var commands = [
// // ['git', ['checkout', __args.branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV]]
// ,
// ]

// var parameters = ['-c', 'for i in `git remote`; do git pull $i ' + branch + '; done;']
// var pullCmd = [ gitbash
// , ['-c', 'for i in `git remote`; do git pull $i ' + branch + '; done;']
// , { cwd: instanceroot + '/' + repo, title : 'pull all origins for ' + branch + ' ' + repo + ' ' + parameters.join(' ') }]



def = def || {
repos : selectedinstance.repos,
@@ -2274,6 +2360,7 @@ var __interactive_prompts = function( target, choices ){
, instanceName : { label : `Enter Instance Name ( <= ${target.instanceName || 'chess'} ) : `, choices : [], defaultchoice : 'chess'}
, instanceType : { label : `Enter Instance Type ( <= ${target.instanceType || 'development'} ) : `, choices : [], defaultchoice : 'development'}
, reposerver : { label : `Enter Instance Name ( <= ${target.reposerver || 'https://git.bbh.org.in'} ) : `, choices : [], defaultchoice : 'https://git.bbh.org.in'}
, repouser : { label : `Enter User Id for ${target.reposerver} ( <= ${target.repouser || 'chess'} ) : `, choices : [], defaultchoice : 'chess'}
}

var eachPrompt = getBoundEachPrompt( target, promptkeys, interactionpoints, choices)

+ 6
- 6
repo-manifest.js Wyświetl plik

@@ -19,9 +19,9 @@ module.exports = ((name, options)=>{
// different based on currently available/accessible to client.
// This is just a list of possible equivalent options.
, { 'origin' : [
`http://git.bbh/${options.gituser}/elxr.git`
, 'https://git.bbh.org.in/${options.gituser}/elxr.git'
, `//172.16.0.27/repos/${options.gituser}/elxr.git`
`http://git.bbh/${options.repouser}/elxr.git`
, `https://git.bbh.org.in/${options.repouser}/elxr.git`
, `//172.16.0.27/repos/${options.repouser}/elxr.git`
]
}
]
@@ -41,8 +41,8 @@ module.exports = ((name, options)=>{

// tracking branches.
// We at least need one branch for each remote that we wish to track.
, 'tracking-branches' : [
{ master : ['origin/master', 'chess/master'] }
]
// , 'tracking-branches' : [
// { master : ['origin/master', 'chess/master'] }
// ]
}
})

Ładowanie…
Anuluj
Zapisz