var child_process = require('child_process');
var fs = require('fs');
var os = require('os');
var path = require('path');


exports.isGitURI = function isGitURI(uri) {
    return !!/^\w+@[\w\.]+:.*/.exec(uri) ||
        !!/ssh:\/\/.*/.exec(uri) ||
        !!/https:\/\/.*\.git/.exec(uri);
};

var gitURICache = {};
exports.cloneGitURI = function cloneGitURI(gitURI, cb) {
    if (gitURICache[gitURI]) {
        cb(null, gitURICache[gitURI]);
        return;
    }

    var tmpDir = os.tmpdir();
    var uniqName = 'shalam' + (Math.random() * 1000000 | 0);
    var newTmpDir = path.resolve(tmpDir, uniqName);

    fs.mkdirSync(newTmpDir);
    gitURICache[gitURI] = newTmpDir;

    var spawned = child_process.spawn('git', ['clone', gitURI, newTmpDir]);

    spawned.on('close', function(code) {
        if (code !== 0) {
            cb('Git returned non-zero exit code');
            return;
        }
        cb(null, newTmpDir);
    });

};

@@ -116,16 +116,150 @@
 ath');%0A%0A
+/**%0A * Returns whether the passed URI is probably for a Git repository.%0A * @param %7Bstring%7D uri The URI to test.%0A * @returns %7Bbool%7D%0A */
 %0Aexports
@@ -446,64 +446,415 @@
 %7B%7D;%0A
-exports.cloneGitURI = function cloneGitURI(gitURI, cb) %7B
+/**%0A * Clones a Git URI to a temporary directory. Calls the callback%0A * function with the temporary directory's path if the clone is%0A * successful.%0A * @param %7Bstring%7D gitURI The URI of the Git repo.%0A * @param %7Bfunction%7D cb The callback to fire on completion or error.%0A * @returns %7Bvoid%7D%0A */%0Aexports.cloneGitURI = function cloneGitURI(gitURI, cb) %7B%0A    // If the URI has already been cloned, return the path.
 %0A   
@@ -943,16 +943,55 @@
 %0A    %7D%0A%0A
+    // Get a temporary directory name.%0A
     var 
@@ -1122,24 +1122,87 @@
 uniqName);%0A%0A
+    // Create the temporary directory and add it to the cache.%0A
     fs.mkdir
@@ -1256,16 +1256,84 @@
 mpDir;%0A%0A
+    // Spawn a %60git clone%60 process and perform the clone operation.%0A
     var 
@@ -1438,24 +1438,79 @@
 ion(code) %7B%0A
+        // Handle non-zero exit codes from %60git clone%60%0A
         if (
@@ -1604,16 +1604,88 @@
       %7D%0A
+        // Fire the success callback with the temporary directory path.%0A
         

Clean up /lib/git.js