Repository: bower/bower
Pull request #2506 (2018-03-28 14:38:34)

Rebased version of #1964


Patch:
diff --git a/lib/commands/lookup.js b/lib/commands/lookup.js
index 9027836d..5d095642 100644
--- a/lib/commands/lookup.js
+++ b/lib/commands/lookup.js
@@ -16,7 +16,7 @@ function lookup(logger, name, config) {
     .then(function (entry) {
         return !entry ? null : {
             name: name,
-            url: entry.url
+            url: entry && entry.url
         };
     });
 }
diff --git a/lib/core/Manager.js b/lib/core/Manager.js
index ed66c4ba..f1f9fcde 100644
--- a/lib/core/Manager.js
+++ b/lib/core/Manager.js
@@ -687,6 +687,7 @@ Manager.prototype._electSuitable = function (name, semvers, nonSemvers) {
     var unresolvable;
     var dataPicks;
     var save;
+    var choices;
     var picks = [];
     var versionRegex = /(?:[\d\w]\.){2}[\d\w](?:.)*/;
     var picksReleases;
@@ -844,6 +845,7 @@ Manager.prototype._electSuitable = function (name, semvers, nonSemvers) {
         picks: dataPicks
     });
 
+    choices = picks.map(function (pick, index) { return index + 1; });
     picksReleases = picks.map(function (pick) { return pick.pkgMeta._release; });
     return Q.nfcall(this._logger.prompt.bind(this._logger), {
         type: 'input',
diff --git a/lib/core/resolvers/GitRemoteResolver.js b/lib/core/resolvers/GitRemoteResolver.js
index 1a8e9be9..b8f32f8b 100644
--- a/lib/core/resolvers/GitRemoteResolver.js
+++ b/lib/core/resolvers/GitRemoteResolver.js
@@ -19,14 +19,14 @@ function GitRemoteResolver(decEndpoint, config, logger) {
         this._name = this._name.slice(0, -4);
     }
 
-    // Get the host of this source
+    // Get the remote of this source
     if (!/:\/\//.test(this._source)) {
-        this._host = url.parse('ssh://' + this._source).host;
+        this._remote = url.parse('ssh://' + this._source);
     } else {
-        this._host = url.parse(this._source).host;
+        this._remote = url.parse(this._source);
     }
-
-    this._remote = url.parse(this._source);
+    
+    this._host = this._remote.host;
 
     // Verify whether the server supports shallow cloning
     this._shallowClone = this._supportsShallowCloning;
diff --git a/lib/core/resolvers/GitResolver.js b/lib/core/resolvers/GitResolver.js
index 90d58c03..b34a839a 100644
--- a/lib/core/resolvers/GitResolver.js
+++ b/lib/core/resolvers/GitResolver.js
@@ -121,6 +121,8 @@ GitResolver.prototype._findResolution = function (target) {
                 version,
                 index;
 
+            versionsArr = versions.map(function (obj) { return obj.version; });
+
             // If there are no tags and target is *,
             // fallback to the latest commit on master
             if (!versions.length && target === '*') {


Test patch:
diff --git a/test/core/resolvers/gitRemoteResolver.js b/test/core/resolvers/gitRemoteResolver.js
index 6381424e..30c7a0bd 100644
--- a/test/core/resolvers/gitRemoteResolver.js
+++ b/test/core/resolvers/gitRemoteResolver.js
@@ -356,6 +356,26 @@ describe('GitRemoteResolver', function () {
             });
         });
 
+        it('should evaluate to true when source is a ssh protocol and host is defined to support shallow cloning', function (next) {
+            var testSource = 'git@foo:bar.git';
+
+            var MyGitRemoteResolver = gitRemoteResolverFactory(
+                createCmdHandlerFn(testSource, multiline(function () {/*
+                    foo: bar
+                    Content-Type: application/x-git-upload-pack-advertisement
+                    1234: 5678
+                */}))
+            );
+
+            var resolver = new MyGitRemoteResolver({ source: testSource }, defaultConfig({ shallowCloneHosts: ['foo'] }), logger);
+
+            resolver._shallowClone().then(function (shallowCloningSupported) {
+                expect(shallowCloningSupported).to.be(true);
+
+                next();
+            });
+        });
+
         it('should cache hosts that support shallow cloning', function (next) {
             var testSource = 'https://foo/bar.git';