You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2013/09/12 20:14:49 UTC
[21/40] git commit: [CB-4622]: Allow git URLs with a hash specifying
git ref and subdir
[CB-4622]: Allow git URLs with a hash specifying git ref and subdir
Format is https://github.com/foo/bar.git#gitref:subdir. Subdir is
optional, so #gitref is valid, and git refs can be omitted to use HEAD
with some subdir (#:subdir).
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/73c3aa72
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/73c3aa72
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/73c3aa72
Branch: refs/heads/ffos
Commit: 73c3aa72046dd649d4dca6660c983ff540f1d01d
Parents: f276c21
Author: Braden Shepherdson <br...@gmail.com>
Authored: Tue Sep 3 15:56:19 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Tue Sep 3 15:56:19 2013 -0400
----------------------------------------------------------------------
spec/fetch.spec.js | 18 ++++++++++++++++++
src/fetch.js | 18 ++++++++++++++++++
2 files changed, 36 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/73c3aa72/spec/fetch.spec.js
----------------------------------------------------------------------
diff --git a/spec/fetch.spec.js b/spec/fetch.spec.js
index 3213ad4..a52228f 100644
--- a/spec/fetch.spec.js
+++ b/spec/fetch.spec.js
@@ -61,6 +61,24 @@ describe('fetch', function() {
fetch(url, temp, { subdir: dir, git_ref: ref });
expect(clone).toHaveBeenCalledWith(url, temp, dir, ref, jasmine.any(Function));
});
+ it('should extract the git ref from the URL hash, if provided', function() {
+ var url = "https://github.com/bobeast/GAPlugin.git#fakeGitRef";
+ var baseURL = "https://github.com/bobeast/GAPlugin.git";
+ fetch(url, temp, {});
+ expect(clone).toHaveBeenCalledWith(baseURL, temp, '.', 'fakeGitRef', jasmine.any(Function));
+ });
+ it('should extract the subdir from the URL hash, if provided', function() {
+ var url = "https://github.com/bobeast/GAPlugin.git#:fakeSubDir";
+ var baseURL = "https://github.com/bobeast/GAPlugin.git";
+ fetch(url, temp, {});
+ expect(clone).toHaveBeenCalledWith(baseURL, temp, 'fakeSubDir', undefined, jasmine.any(Function));
+ });
+ it('should extract the git ref and subdir from the URL hash, if provided', function() {
+ var url = "https://github.com/bobeast/GAPlugin.git#fakeGitRef:/fake/Sub/Dir/";
+ var baseURL = "https://github.com/bobeast/GAPlugin.git";
+ fetch(url, temp, {});
+ expect(clone).toHaveBeenCalledWith(baseURL, temp, 'fake/Sub/Dir', 'fakeGitRef', jasmine.any(Function));
+ });
it('should throw if used with url and `link` param', function() {
expect(function() {
fetch("https://github.com/bobeast/GAPlugin.git", temp, {link:true});
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/73c3aa72/src/fetch.js
----------------------------------------------------------------------
diff --git a/src/fetch.js b/src/fetch.js
index 59b95cf..5d36b3f 100644
--- a/src/fetch.js
+++ b/src/fetch.js
@@ -18,6 +18,24 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options, callback
// clone from git repository
var uri = url.parse(plugin_dir);
+
+ // If the hash exists, it has the form from npm: http://foo.com/bar#git-ref[:subdir]
+ // NB: No leading or trailing slash on the subdir.
+ if (uri.hash) {
+ var result = uri.hash.match(/^#([^:]*)(?::\/?(.*?)\/?)?$/);
+ if (result) {
+ if (result[1])
+ options.git_ref = result[1];
+ if(result[2])
+ options.subdir = result[2];
+
+ // Recurse and exit with the new options and truncated URL.
+ var new_dir = plugin_dir.substring(0, plugin_dir.indexOf('#'));
+ module.exports(new_dir, plugins_dir, options, callback);
+ return;
+ }
+ }
+
if ( uri.protocol && uri.protocol != 'file:' && !plugin_dir.match(/^\w+:\\/)) {
if (options.link) {
var err = new Error('--link is not supported for git URLs');