You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/05/16 17:57:09 UTC

[10/20] git commit: Add git ref support to fetch. Not used anywhere yet.

Add git ref support to fetch. Not used anywhere yet.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/2e5f15f5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/2e5f15f5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/2e5f15f5

Branch: refs/heads/master
Commit: 2e5f15f57c9bfc216b2eac986c38f51e0229050d
Parents: 01c3d7a
Author: Braden Shepherdson <br...@gmail.com>
Authored: Tue May 14 17:10:50 2013 -0400
Committer: Fil Maj <ma...@gmail.com>
Committed: Thu May 16 08:55:42 2013 -0700

----------------------------------------------------------------------
 spec/fetch.spec.js  |   10 +++++++++-
 src/fetch.js        |    4 ++--
 src/install.js      |    3 ++-
 src/util/plugins.js |   12 +++++++++++-
 4 files changed, 24 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/2e5f15f5/spec/fetch.spec.js
----------------------------------------------------------------------
diff --git a/spec/fetch.spec.js b/spec/fetch.spec.js
index 8f7c678..79afaa4 100644
--- a/spec/fetch.spec.js
+++ b/spec/fetch.spec.js
@@ -42,7 +42,15 @@ describe('fetch', function() {
             var url = "https://github.com/bobeast/GAPlugin.git";
             var dir = 'fakeSubDir';
             fetch(url, temp, false, dir);
-            expect(s).toHaveBeenCalledWith(url, temp, dir, undefined);
+            expect(s).toHaveBeenCalledWith(url, temp, dir, undefined, undefined);
+        });
+        it('should call clonePluginGitRepo with subdir and git ref if applicable', function() {
+            var s = spyOn(plugins, 'clonePluginGitRepo');
+            var url = "https://github.com/bobeast/GAPlugin.git";
+            var dir = 'fakeSubDir';
+            var ref = 'fakeGitRef';
+            fetch(url, temp, false, dir, ref);
+            expect(s).toHaveBeenCalledWith(url, temp, dir, ref, undefined);
         });
         it('should throw if used with url and `link` param', function() {
             expect(function() {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/2e5f15f5/src/fetch.js
----------------------------------------------------------------------
diff --git a/src/fetch.js b/src/fetch.js
index 73bf4e2..a222af6 100644
--- a/src/fetch.js
+++ b/src/fetch.js
@@ -4,7 +4,7 @@ var shell   = require('shelljs'),
     xml_helpers = require('./util/xml-helpers'),
     path    = require('path');
 
-module.exports = function fetchPlugin(plugin_dir, plugins_dir, link, subdir, callback) {
+module.exports = function fetchPlugin(plugin_dir, plugins_dir, link, subdir, git_ref, callback) {
     // Ensure the containing directory exists.
     shell.mkdir('-p', plugins_dir);
 
@@ -17,7 +17,7 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, link, subdir, cal
             if (callback) callback(err);
             else throw err;
         } else {
-            plugins.clonePluginGitRepo(plugin_dir, plugins_dir, subdir, callback);
+            plugins.clonePluginGitRepo(plugin_dir, plugins_dir, subdir, git_ref, callback);
         }
     } else {
         // Copy from the local filesystem.

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/2e5f15f5/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index f73f5f3..74c8e41 100644
--- a/src/install.js
+++ b/src/install.js
@@ -21,7 +21,8 @@ module.exports = function installPlugin(platform, project_dir, id, plugins_dir,
     // Check that the plugin has already been fetched.
     if (!fs.existsSync(plugin_dir)) {
         // if plugin doesnt exist, use fetch to get it.
-        require('../plugman').fetch(id, plugins_dir, false, subdir, function(err, plugin_dir) {
+        // TODO: Actual value for git_ref.
+        require('../plugman').fetch(id, plugins_dir, false, '.', undefined /* git_ref */, function(err, plugin_dir) {
             if (err) {
                 callback(err);
             } else {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/2e5f15f5/src/util/plugins.js
----------------------------------------------------------------------
diff --git a/src/util/plugins.js b/src/util/plugins.js
index d5141cb..f1b3f0b 100644
--- a/src/util/plugins.js
+++ b/src/util/plugins.js
@@ -30,7 +30,7 @@ var http = require('http'),
 module.exports = {
     searchAndReplace:require('./search-and-replace'),
     // Fetches plugin information from remote server
-    clonePluginGitRepo:function(plugin_git_url, plugins_dir, subdir, callback) {
+    clonePluginGitRepo:function(plugin_git_url, plugins_dir, subdir, git_ref, callback) {
         if(!shell.which('git')) {
             var err = new Error('git command line is not installed');
             if (callback) callback(err);
@@ -46,6 +46,16 @@ module.exports = {
                 if (callback) callback(err)
                 else throw err;
             } else {
+                // Check out the specified revision, if provided.
+                if (git_ref) {
+                    var result = shell.exec(util.format('git checkout "%s"', git_ref), { silent: true });
+                    if (result.code > 0) {
+                        var err = new Error('failed to checkout git ref "' + git_ref + '"');
+                        if (callback) callback(err);
+                        else throw err;
+                    }
+                }
+
                 // Read the plugin.xml file and extract the plugin's ID.
                 tmp_dir = path.join(tmp_dir, subdir);
                 // TODO: what if plugin.xml does not exist?