Comparing version 0.2.7 to 0.2.8
@@ -73,6 +73,9 @@ var fs = require('fs'); | ||
function $git(dir, args, ignoreErrors) { | ||
var onerror = function() {}; | ||
// just complete operation indicating error | ||
var onerror = function(err, cb) { return cb(err)}; | ||
if (typeof ignoreErrors === 'function') { | ||
// custom error handler specified (it should call completion) | ||
onerror = ignoreErrors; | ||
// if there is custom error handler, errors are not ignored | ||
ignoreErrors = false; | ||
@@ -89,4 +92,4 @@ } | ||
return git(args, opts, function(err) { | ||
if (err && onerror) return onerror(err, cb); | ||
return cb(err); | ||
if (err) return onerror(err, cb); | ||
return cb(); | ||
}); | ||
@@ -136,35 +139,2 @@ }; | ||
/** | ||
* Promise to initialize the repository. | ||
* If the repository seems to be corrupted (exit code 128), it will be recreated. | ||
*/ | ||
function $init(dir) { | ||
return function(cb) { | ||
return async.series([ | ||
$mkdirp(dir), | ||
$git(dir, ['init', '--bare'], function(err, cb) { | ||
// exit code 128 indicates an unexpected error. | ||
// http://stackoverflow.com/questions/4917871/does-git-return-specific-return-error-codes | ||
if (err && err.exitCode === 128) { | ||
logger.warn(dir + ' seems to be corrupted. Trying to recreate.'); | ||
// rm -fr dir | ||
return rimraf(dir, function(err) { | ||
if (err) { | ||
logger.error('Unable to clean up (rm -fr) ' + dir); | ||
return cb(err); | ||
} | ||
// try init again | ||
return $init(dir)(cb); | ||
}); | ||
} | ||
return cb(err); | ||
}), | ||
], cb); | ||
}; | ||
} | ||
/** | ||
* Returns the system's temp directory | ||
@@ -213,3 +183,2 @@ */ | ||
remote = remote_type(remote); | ||
if (!branch) branch = 'master'; // default branch in case it was not defined anywhere | ||
@@ -221,29 +190,50 @@ | ||
return async.series([ | ||
return function girrorseq() { | ||
async.series([ | ||
// make sure we have a bare repo to work with | ||
$log('bare repository under: ' + dirpath), | ||
$init(dirpath), | ||
// make sure we have a bare repo to work with | ||
$log('bare repository under: ' + dirpath), | ||
$mkdirp(dirpath), | ||
$git(dirpath, ['init', '--bare']), // will not harm an existing repo | ||
// git remote rm/add origin | ||
$log('setting up remote origin to ' + remote), | ||
$git(dirpath, ['remote', 'add', 'origin', '--mirror=fetch', remote], true), // ignore errors (in case remote already exist) | ||
// git remote rm/add origin | ||
$log('setting up remote origin to ' + remote), | ||
$git(dirpath, ['remote', 'add', 'origin', '--mirror=fetch', remote], true), // ignore errors (in case remote already exist) | ||
// git fetch origin | ||
$log('fetching updates from ' + remote), | ||
$if( | ||
depth === -1, | ||
$git(dirpath, [ 'fetch', 'origin' ]), | ||
$git(dirpath, [ 'fetch', '--depth', depth, 'origin' ]) | ||
), | ||
// git fetch origin | ||
$log('fetching updates from ' + remote), | ||
$if( | ||
depth === -1, | ||
$git(dirpath, [ 'fetch', 'origin' ]), | ||
$git(dirpath, [ 'fetch', '--depth', depth, 'origin' ]) | ||
), | ||
// make sure worktree exists | ||
$log('checking out branch ' + branch + ' into ' + worktree), | ||
$mkdirp(worktree), | ||
$git(dirpath, [ '--work-tree', worktree, 'checkout', '-f', branch ]), | ||
// make sure worktree exists | ||
$log('checking out branch ' + branch + ' into ' + worktree), | ||
$mkdirp(worktree), | ||
$git(dirpath, [ '--work-tree', worktree, 'checkout', '-f', branch ]), | ||
// create girrorfile | ||
$girrorfile(worktree, girrorfile, remote_input, branch), | ||
// create girrorfile | ||
$girrorfile(worktree, girrorfile, remote_input, branch), | ||
], callback); | ||
], function(err) { | ||
// exit code 128 indicates an unexpected error. | ||
// http://stackoverflow.com/questions/4917871/does-git-return-specific-return-error-codes | ||
if (err && err.exitCode === 128) { | ||
logger.warn(dirpath + ' seems to be corrupted. Trying to recreate.'); | ||
// rm -fr dir | ||
return rimraf(dirpath, function(err) { | ||
if (err) { | ||
logger.error('Unable to clean up (rm -fr) ' + dirpath); | ||
return callback(err); | ||
} | ||
// try again | ||
return girrorseq(); | ||
}); | ||
} | ||
return callback(err); | ||
}); | ||
}(); | ||
}); | ||
@@ -250,0 +240,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"description": "Efficient mirror of git repositories. Great for continuous deployment", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
0
42654
416