Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

git-clone

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-clone - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

private/impl.js

42

index.js

@@ -1,5 +0,4 @@

var spawn = require('child_process').spawn;
const impl = require('./private/impl');
module.exports = function(repo, targetPath, opts, cb) {
if (typeof opts === 'function') {

@@ -11,40 +10,5 @@ cb = opts;

opts = opts || {};
cb = cb || function() {};
var git = opts.git || 'git';
var args = ['clone'];
if (opts.shallow) {
args.push('--depth');
args.push('1');
}
args.push('--');
args.push(repo);
args.push(targetPath);
var process = spawn(git, args);
process.on('close', function(status) {
if (status == 0) {
if (opts.checkout) {
_checkout();
} else {
cb && cb();
}
} else {
cb && cb(new Error("'git clone' failed with status " + status));
}
});
function _checkout() {
var args = ['checkout', opts.checkout];
var process = spawn(git, args, { cwd: targetPath });
process.on('close', function(status) {
if (status == 0) {
cb && cb();
} else {
cb && cb(new Error("'git checkout' failed with status " + status));
}
});
}
impl(repo, targetPath, opts, cb, cb);
}
{
"name": "git-clone",
"version": "0.1.0",
"version": "0.2.0",
"description": "Clone a git repository",

@@ -5,0 +5,0 @@ "main": "index.js",

# git-clone
Clone a git repository via shell command.
Clone a git repository via `git` shell command.

@@ -9,24 +9,41 @@ ## Installation

$ npm install git-clone
$ npm install git-clone
Require:
To use the original callback-based API:
var clone = require('git-clone');
const clone = require('git-clone');
As of 0.2.0 there's a promised-based API for use with `async`/`await`:
const clone = require('git-clone/promise');
## API
## Common Options
* `git`: path to `git` binary; default: `git` (expected to be in your `$PATH`)
* `shallow`: when `true`, clone with depth 1
* `checkout`: revision/branch/tag to check out after clone
* `args`: additional array of arguments to pass to `git clone`
## Callback
#### `clone(repo, targetPath, [options], cb)`
Clone `repo` to `targetPath`, calling `cb` on completion.
Clone `repo` to `targetPath`, calling `cb` on completion; any error that occurred will be passed as the first argument. If no error is passed the `git clone` operation was successful.
Supported `options`:
## Promise
* `git`: path to `git` binary; default: `git` (optional).
* `shallow`: when `true`, clone with depth 1 (optional).
* `checkout`: revision/branch/tag to check out (optional).
#### `async clone(repo, targetPath, [options])`
Clone `repo` to `targetPath`, throwing an exception on failure.
## Contributors
- [AntiMoron](https://github.com/AntiMoron)
## Copyright & License
© 2014 Jason Frame [ [@jaz303](http://twitter.com/jaz303) / [jason@onehackoranother.com](mailto:jason@onehackoranother.com) ]
© 2014-2021 Jason Frame & Contributors [ [@jaz303](http://twitter.com/jaz303) / [jason@onehackoranother.com](mailto:jason@onehackoranother.com) ]
Released under the ISC license.

@@ -1,8 +0,59 @@

var gitClone = require('../index');
const fs = require('fs');
const {execSync} = require('child_process');
gitClone('git@github.com:jaz303/tpl-simple-site.git', './test-checkout', {
checkout: 'a76362b0705d4126fa4462916cabb2506ecfe8e2' },
function(err) {
console.log("complete!");
console.log(err);
const gitClone = {
callback: require('../'),
promise: require('../promise')
};
function assertGitRepoSync(dir, revision) {
const stats = fs.statSync(`${dir}/.git`);
return stats.isDirectory();
}
function assertCheckout(dir, expectedCheckout) {
const checkedOut = execSync('git rev-parse HEAD', {cwd: dir, encoding: 'utf8'}).trim();
return checkedOut === expectedCheckout;
}
let nextCheckoutId = 1;
function runTestCase(name, opts, fn) {
const id = nextCheckoutId++;
const targetDir = `./test-checkout-${Date.now()}-${id}`;
fn(targetDir, opts, (err) => {
if (err) {
console.error(`Test '${name}' failed: ${err.message}`);
} else if (!assertGitRepoSync(targetDir)) {
console.error(`Test '${name}' failed: target directory is not a git repository`);
} else if (opts && opts.checkout && !assertCheckout(targetDir, opts.checkout)) {
console.error(`Test '${name}' failed: incorrect checkout`);
} else {
console.error(`Test '${name}': OK`);
}
execSync(`rm -rf ${targetDir}`);
});
}
const callbackTest = (targetDir, options, onComplete) => {
if (options === null) {
gitClone.callback('git@github.com:jaz303/git-clone.git', targetDir, onComplete);
} else {
gitClone.callback('git@github.com:jaz303/git-clone.git', targetDir, options, onComplete);
}
};
const promiseTest = async (targetDir, options, onComplete) => {
try {
await gitClone.promise('git@github.com:jaz303/git-clone.git', targetDir, options);
onComplete(null);
} catch (err) {
onComplete(err);
}
}
runTestCase('callback', {}, callbackTest);
runTestCase('callback (null options)', null, callbackTest); // tests argument juggling
runTestCase('callback with checkout', {checkout: 'ddb88d4d1dca74e8330eccb7997badd6a6906b98'}, callbackTest);
runTestCase('promise', {}, promiseTest);
runTestCase('promise with checkout', {checkout: 'ddb88d4d1dca74e8330eccb7997badd6a6906b98'}, promiseTest);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc