Comparing version
@@ -6,2 +6,3 @@ var fs = require('fs'); | ||
var mkdirp = require('mkdirp'); | ||
var rimraf = require('rimraf'); | ||
var con = require('ctxobj').console; | ||
@@ -73,2 +74,9 @@ var git = require('./git'); | ||
function $git(dir, args, ignoreErrors) { | ||
var onerror = function() {}; | ||
if (typeof ignoreErrors === 'function') { | ||
onerror = ignoreErrors; | ||
ignoreErrors = false; | ||
} | ||
return function(cb) { | ||
@@ -81,3 +89,6 @@ var opts = { logger: logger, tolerate: ignoreErrors }; | ||
return git(args, opts, cb); | ||
return git(args, opts, function(err) { | ||
if (err && onerror) return onerror(err, cb); | ||
return cb(err); | ||
}); | ||
}; | ||
@@ -126,2 +137,35 @@ } | ||
/** | ||
* 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 | ||
@@ -181,4 +225,3 @@ */ | ||
$log('bare repository under: ' + dirpath), | ||
$mkdirp(dirpath), | ||
$git(dirpath, ['init', '--bare']), // will not harm an existing repo | ||
$init(dirpath), | ||
@@ -185,0 +228,0 @@ // git remote rm/add origin |
@@ -61,3 +61,6 @@ var spawn = require('child_process').spawn; | ||
var err = (tolerate || code === 0) ? null : new Error('"' + command + '" exited with status ' + code + ':\n' + errors.join('')); | ||
if (err) logger.error(err); | ||
if (err) { | ||
logger.error(err); | ||
err.exitCode = code; | ||
} | ||
return callback(err); | ||
@@ -64,0 +67,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"description": "Efficient mirror of git repositories. Great for continuous deployment", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"repository": { | ||
@@ -23,3 +23,4 @@ "type": "git", | ||
"commander": "0.5.2", | ||
"logule": "0.6.1" | ||
"logule": "0.6.1", | ||
"rimraf": "2.0.2" | ||
}, | ||
@@ -26,0 +27,0 @@ "devDependencies": {}, |
Sorry, the diff of this file is not supported yet
42661
3.68%422
10.18%6
20%+ Added
+ Added
+ Added