Created
October 7, 2015 20:44
-
-
Save AubreyHewes/17a955f4e46c6c5eff08 to your computer and use it in GitHub Desktop.
nodegit 0.5.0 push to remote failure poc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env /usr/bin/node | |
/** | |
* NOTE: Run in a project root that already has a remote configured | |
* | |
* # v0.5.0 (this is the npm default version) | |
* | |
* `npm install nodegit@^v0.5.0` | |
* | |
* NOTE: DOES_NOT fetch from S3 (see also https://github.com/nodegit/nodegit/issues/736) | |
* | |
* Try 1 - Trying with `remote.initCallbacks(callbacks)` - api doc states it should be this | |
* * FAIL: Error: remote.initCallbacks is undefined | |
* | |
* Try 2 - Trying with `remote.setCallbacks(callbacks)` - this is the old method; so expected failure | |
* * FAIL: Error: remote.setCallbacks is undefined | |
* | |
* Try 3 - Trying with `remote.connect(opt, callbacks)` | |
* * FAIL: Error: Must call UPLOADPACK_LS before UPLOADPACK | |
* | |
* # v0.4.1 | |
* `npm install nodegit@^v0.4.1` | |
* | |
* NOTE: DOES fetch from S3 | |
* | |
* Try 1 - Trying with `remote.initCallbacks(callbacks)` - api doc states it should be this | |
* * FAIL: Error: remote.initCallbacks is undefined | |
* | |
* Try 2 - Trying with `remote.setCallbacks(callbacks)` - this is the old, undocumented, method; that works on 0.4.1 | |
* * SUCCESS | |
*/ | |
var VERSIONS = ['0.5.0', '0.4.1']; | |
var exec = require('child_process').exec; | |
console.info('Running against nodegit versions: ' + VERSIONS.join(', ')); | |
var pathToRepo = require("path").resolve(__dirname, '.git'); | |
console.info('Repo: ' + pathToRepo +'\n'); | |
// install bluebird for later | |
console.info('Initialising...'); | |
console.info(' > Installing bluebird...'); | |
var init = exec('npm install bluebird'); | |
init.stdout.on('data', function (data) { | |
console.log(data); | |
}); | |
init.stderr.on('data', function (data) { | |
console.error(data); | |
}); | |
init.addListener("exit", run); | |
// run it now we know we have bluebird | |
function run() { | |
var Promise = require("bluebird"); | |
Promise.each(VERSIONS, function (version) { | |
return npmInstallVersion(version).then(doIt); | |
}).then(function () { | |
console.info("===================================================================================================\nDone."); | |
}); | |
function npmInstallVersion(version) { | |
console.info("\n==================================================================================================="); | |
console.info('Installing nodegit version ' + version); | |
var child = exec("npm install nodegit@^" + version); | |
child.stdout.on('data', function (data) { | |
console.log(data); | |
}); | |
child.stderr.on('data', function (data) { | |
console.error(data); | |
}); | |
return new Promise(function (resolve, reject) { | |
child.addListener("error", reject); | |
child.addListener("exit", resolve); | |
}); | |
} | |
var repo, remote; | |
function doPush() { | |
return remote.push( | |
["refs/heads/master:refs/heads/master"], | |
null, | |
repo.defaultSignature(), | |
"Push to master" | |
).then(function() { | |
console.log(' => SUCCESS!') | |
}); | |
} | |
var remoteCallbacks = { | |
credentials: function(url, userName) { | |
return NodeGit.Cred.sshKeyFromAgent(userName); | |
}, | |
transferProgress: function(info) { | |
return console.info(info); | |
} | |
}; | |
var NodeGit; | |
function doIt() { | |
NodeGit = require("nodegit"); | |
console.info("---------------------------------------------------------------------------------------------------"); | |
console.info('Running (try to push to remote)'); | |
return NodeGit.Repository.open(pathToRepo) | |
.then(function(repoResult) { | |
repo = repoResult; | |
return repo.getRemote('origin'); | |
}) | |
.then(function(remoteResult) { | |
remote = remoteResult; | |
try { | |
console.info(' (1) Trying with remote.initCallbacks(callbacks)'); | |
remote.initCallbacks(remoteCallbacks); | |
} catch (ex) { | |
console.error(' => FAIL (1) Trying with remote.initCallbacks(callbacks)', ex); | |
console.info(' (2) Trying with remote.setCallbacks(callbacks)'); | |
remote.setCallbacks(remoteCallbacks); | |
} | |
return remote.connect(NodeGit.Enums.DIRECTION.PUSH).then(doPush); | |
}) | |
.catch(function () { | |
console.error(' => FAIL (2) Trying with remote.setCallbacks(callbacks)', arguments); | |
console.info(' (3) Trying with callbacks in remote.connect(opt, callbacks)'); | |
remote.connect(NodeGit.Enums.DIRECTION.PUSH, remoteCallbacks).then(doPush).catch(function() { | |
console.error(' => FAIL (3) Trying with callbacks in remote.connect(opt, callbacks)', arguments); | |
}).then(doPush); | |
}) | |
.catch(function () { | |
console.error('UNEXPECTED', arguments); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment