Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
github: fix the ssh fallback for private github modules
Browse files Browse the repository at this point in the history
This only impacts github modules installed via github shortcuts, eg

    npm install project/module

When the module is marked as private.
  • Loading branch information
iarna authored and othiym23 committed Mar 27, 2015
1 parent 94df809 commit eab6184
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/cache/maybe-github.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ module.exports = function maybeGithub (p, cb) {
return addRemoteGit(parsed.git(), true, function (er, data) {
if (er) {
log.info("maybeGithub", "Couldn't clone %s", parsed.git())
log.info("maybeGithub", "Now attempting %s from %s", p, parsed.ssh())
log.info("maybeGithub", "Now attempting %s from %s", p, parsed.sshurl())

return addRemoteGit(parsed.ssh(), false, function (er, data) {
return addRemoteGit(parsed.sshurl(), false, function (er, data) {
if (er) return cb(er)

success(parsed.ssh(), data)
success(parsed.sshurl(), data)
})
}

Expand Down
32 changes: 32 additions & 0 deletions test/tap/github-shortcut.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict'
var requireInject = require('require-inject')
var test = require('tap').test

test('github-shortcut', function (t) {
var cloneUrls = [
['git://github.com/foo/private.git', 'github shortcuts try git:// first'],
['ssh://git@github.com/foo/private.git', 'github shortcuts try ssh:// urls second']
]
var npm = requireInject.installGlobally('../../lib/npm.js', {
'child_process': {
'execFile': function (cmd, args, options, cb) {
process.nextTick(function () {
if (args[0] !== 'clone') return cb(null, '', '')
var cloneUrl = cloneUrls.shift()
if (cloneUrl) {
t.is(args[3], cloneUrl[0], cloneUrl[1])
} else {
t.fail('too many attempts to clone')
}
cb(new Error())
})
}
}
})

npm.load({loglevel: 'silent'}, function () {
npm.commands.install(['foo/private'], function (er, result) {
t.end()
})
})
})

0 comments on commit eab6184

Please sign in to comment.