|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"use strict"; |
|
|
|
|
|
|
|
var fs = require('fs'); |
|
var path = require('path'); |
|
var cwd = process.cwd(); |
|
var run = require(cwd + '/src/run'); |
|
|
|
function sync(config, hdl) { |
|
if (config.patch === undefined) { |
|
hdl('ERROR -- no patch'); |
|
return; |
|
} |
|
if (config.repository === undefined) { |
|
hdl('ERROR -- no repository'); |
|
return; |
|
} |
|
if (config.name === undefined) { |
|
hdl('ERROR -- no name'); |
|
return; |
|
} |
|
var path = config.repository + '/' + config.name; |
|
if (path === undefined) { |
|
hdl('ERROR -- no path'); |
|
return; |
|
} |
|
|
|
run.exec('git', ['clean', '-f', '-d'], path, function(err, stdout, stderr) { |
|
if (err) { |
|
|
|
hdl(err, stdout, stderr); |
|
return; |
|
} |
|
run.exec('git', ['fetch'], path, function(err, stdout, stderr) { |
|
if (err) { |
|
|
|
hdl(err, stdout, stderr); |
|
return; |
|
} |
|
run.exec('git', ['reset', '--hard', config.patch], path, |
|
function(err, stdout, stderr) { |
|
if (err) { |
|
|
|
hdl(err, stdout, stderr); |
|
return; |
|
} |
|
run.exec('git', ['log', '-n1', '--pretty=format:"%H"'], path, |
|
function(err, stdout, stderr) { |
|
if (err) { |
|
|
|
hdl(err, stdout, stderr); |
|
return; |
|
} |
|
if (stdout.indexOf(config.patch) === -1) { |
|
hdl('ERROR, git sync ' + |
|
'-- bad sync, config.patch not corresponding.' + |
|
' should be ' + config.patch + ' is ' + stdout); |
|
} else |
|
hdl(undefined); |
|
}); |
|
}); |
|
}); |
|
}); |
|
} |
|
|
|
function clone(config, hdl) { |
|
|
|
|
|
if (config.url === undefined) { |
|
hdl('ERROR -- no url'); |
|
return; |
|
} |
|
if (config.repository === undefined) { |
|
hdl('ERROR -- no repository'); |
|
return; |
|
} |
|
if (config.name === undefined) { |
|
hdl('ERROR -- no name'); |
|
return; |
|
} |
|
var tpath = path.normalize(config.repository + '/' + config.name); |
|
if (tpath === undefined) { |
|
hdl('ERROR -- no path'); |
|
return; |
|
} |
|
|
|
if (fs.existsSync(tpath)) |
|
hdl(undefined); |
|
else { |
|
console.log('Need to clone repo', config); |
|
|
|
var args = ['clone', config.url, tpath]; |
|
|
|
|
|
|
|
run.exec('git', args, null, function(err, stdout, stderr) { |
|
|
|
hdl(err, stdout, stderr); |
|
}); |
|
} |
|
} |
|
|
|
module.exports.sync = sync; |
|
module.exports.clone = clone; |
|
|