New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

git-cli

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-cli - npm Package Compare versions

Comparing version
0.6.2
to
0.7.0
+93
-121
lib/repository.js
(function() {
var CliCommand, CliOption, GitUtil, Repository, Runner, S, Util, errors, fs, path, _;
var CliCommand, CliOption, Repository, S, errors, execute, fs, gitUtil, path, util, _;

@@ -18,7 +18,7 @@ fs = require('fs-extra');

Runner = require('./runner');
execute = require('./runner').execute;
Util = require('./util');
util = require('./util');
GitUtil = require('./git-util');
gitUtil = require('./git-util');

@@ -38,30 +38,20 @@ Repository = (function() {

Repository.init = function(path, options, callback) {
var command, done, _ref;
_ref = Util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
var cb, command, _ref;
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
fs.ensureDirSync(path);
command = new CliCommand('git', ['init', path], options);
if (callback) {
done = callback;
callback = function(err, stdout, stderr) {
var repository;
repository = new Repository("" + path + "/.git");
return done(err, repository);
};
}
return Runner.execute(command, {}, callback);
cb = util.wrapCallback(callback, (function() {
return new Repository("" + path + "/.git");
}));
return execute(command, {}, cb);
};
Repository.clone = function(url, path, options, callback) {
var command, done, _ref;
_ref = Util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
var cb, command, _ref;
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
command = new CliCommand(['git', 'clone'], [url, path], options);
if (callback) {
done = callback;
callback = function(err, stdout, stderr) {
var repository;
repository = new Repository("" + path + "/.git");
return done(err, repository);
};
}
return Runner.execute(command, {}, callback);
cb = util.wrapCallback(callback, (function() {
return new Repository("" + path + "/.git");
}));
return execute(command, {}, cb);
};

@@ -72,5 +62,5 @@

if (_.isArray(files)) {
_ref = Util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
} else {
_ref1 = Util.setOptions(files, options), options = _ref1[0], callback = _ref1[1];
_ref1 = util.setOptions(files, options), options = _ref1[0], callback = _ref1[1];
files = ['.'];

@@ -81,25 +71,21 @@ }

command = new CliCommand(['git', 'add'], args, options);
return Runner.execute(command, this._getOptions(), callback);
return execute(command, this._getOptions(), callback);
};
Repository.prototype.status = function(options, callback) {
var command, done, _ref;
_ref = Util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
var cb, command, _ref;
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
command = new CliCommand(['git', 'status'], _.extend({
s: ''
}, options));
if (callback != null) {
done = callback;
callback = (function(_this) {
return function(err, stdout, stderr) {
var statusInfo;
statusInfo = GitUtil.parseStatus(stdout);
_.each(statusInfo, function(f) {
return f.fullPath = "" + (_this.workingDir()) + "/" + f.path;
});
return done(err, statusInfo);
};
})(this);
}
return Runner.execute(command, this._getOptions(), callback);
cb = util.wrapCallback(callback, (function(_this) {
return function(err, stdout) {
var statusInfo;
statusInfo = gitUtil.parseStatus(stdout);
return _.each(statusInfo, function(f) {
return f.fullPath = "" + (_this.workingDir()) + "/" + f.path;
});
};
})(this));
return execute(command, this._getOptions(), cb);
};

@@ -109,11 +95,11 @@

var args, command, _ref;
_ref = Util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
args = this._getDiffArgs(options);
command = new CliCommand(['git', 'diff'], args, options);
return Runner.execute(command, this._getOptions(), callback);
return execute(command, this._getOptions(), callback);
};
Repository.prototype.diffStats = function(options, callback) {
var args, cliOpts, command, done, _ref;
_ref = Util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
var args, cb, cliOpts, command, _ref;
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
args = this._getDiffArgs(options);

@@ -124,19 +110,14 @@ cliOpts = _.extend({

command = new CliCommand(['git', 'diff'], args, cliOpts);
if (callback) {
done = callback;
callback = function(err, stdout, stderr) {
var stats;
stats = GitUtil.parseShortDiff(stdout);
return done(err, stats);
};
}
return Runner.execute(command, this._getOptions(), callback);
cb = util.wrapCallback(callback, function(err, stdout) {
return gitUtil.parseShortDiff(stdout);
});
return execute(command, this._getOptions(), cb);
};
Repository.prototype.log = function(options) {
var callback, cliOpts, command, done, format, _ref;
var callback, cb, cliOpts, command, format, _ref;
if (options == null) {
options = {};
}
_ref = Util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
format = '{"author": "%an", "email": "%ae", "date": "%cd", "subject": "%s", "body": "%b", "hash": "%H"},';

@@ -147,11 +128,6 @@ cliOpts = _.extend({

command = new CliCommand(['git', 'log'], cliOpts);
if (callback) {
done = callback;
callback = function(err, stdout, stderr) {
var logs;
logs = GitUtil.parseLog(stdout);
return done(err, logs);
};
}
return Runner.execute(command, this._getOptions(), callback);
cb = util.wrapCallback(callback, function(err, stdout) {
return gitUtil.parseLog(stdout);
});
return execute(command, this._getOptions(), cb);
};

@@ -161,3 +137,3 @@

var cliOpts, command, _ref;
_ref = Util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
cliOpts = _.extend({

@@ -170,3 +146,3 @@ m: message

command = new CliCommand(['git', 'commit'], cliOpts);
return Runner.execute(command, this._getOptions(), callback);
return execute(command, this._getOptions(), callback);
};

@@ -191,48 +167,33 @@

Repository.prototype.listRemotes = function(options, callback) {
var command, done, _ref;
_ref = Util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
if (callback) {
done = callback;
callback = function(err, stdout, stderr) {
var remotes;
remotes = stdout.trim().split("\n");
return done(err, remotes);
};
}
var cb, command, _ref;
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
cb = util.wrapCallback(callback, function(err, stdout) {
return stdout.trim().split("\n");
});
command = new CliCommand(['git', 'remote', 'show'], options);
return Runner.execute(command, this._getOptions(), callback);
return execute(command, this._getOptions(), cb);
};
Repository.prototype.showRemote = function(name, options, callback) {
var command, done, _ref;
_ref = Util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
if (callback != null) {
done = callback;
callback = function(err, stdout, stderr) {
var remoteInfo;
remoteInfo = GitUtil.parseRemote(stdout);
return done(err, remoteInfo);
};
}
var cb, command, _ref;
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
cb = util.wrapCallback(callback, function(err, stdout) {
return gitUtil.parseRemote(stdout);
});
command = new CliCommand(['git', 'remote', 'show'], name, options);
return Runner.execute(command, this._getOptions(), callback);
return execute(command, this._getOptions(), cb);
};
Repository.prototype.currentBranch = function(options, callback) {
var command, done, _ref;
_ref = Util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
if (callback) {
done = callback;
callback = function(err, stdout, stderr) {
var branch;
branch = GitUtil.parseCurrentBranch(stdout);
return done(err, branch);
};
}
var cb, command, _ref;
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
cb = util.wrapCallback(callback, function(err, stdout) {
return gitUtil.parseCurrentBranch(stdout);
});
command = new CliCommand(['git', 'branch'], options);
return Runner.execute(command, this._getOptions(), callback);
return execute(command, this._getOptions(), cb);
};
Repository.prototype.branch = function(branch, options, callback) {
var command, done, hasName, _ref, _ref1, _ref2, _ref3;
var cb, command, hasName, _ref, _ref1, _ref2, _ref3;
if (_.isString(branch)) {

@@ -242,5 +203,5 @@ branch = [branch];

if (_.isArray(branch)) {
_ref = [Util.setOptions(options, callback), true], (_ref1 = _ref[0], options = _ref1[0], callback = _ref1[1]), hasName = _ref[1];
_ref = [util.setOptions(options, callback), true], (_ref1 = _ref[0], options = _ref1[0], callback = _ref1[1]), hasName = _ref[1];
} else {
_ref2 = [Util.setOptions(branch, options), false], (_ref3 = _ref2[0], options = _ref3[0], callback = _ref3[1]), hasName = _ref2[1];
_ref2 = [util.setOptions(branch, options), false], (_ref3 = _ref2[0], options = _ref3[0], callback = _ref3[1]), hasName = _ref2[1];
}

@@ -250,12 +211,9 @@ if (!hasName) {

}
if ((callback != null) && !hasName) {
done = callback;
callback = function(err, stdout, stderr) {
var branches;
branches = GitUtil.parseBranches(stdout);
return done(err, branches);
};
}
cb = util.wrapCallback(callback, function(err, stdout) {
if (!hasName) {
return gitUtil.parseBranches(stdout);
}
});
command = new CliCommand(['git', 'branch'], branch, options);
return Runner.execute(command, this._getOptions(), callback);
return execute(command, this._getOptions(), cb);
};

@@ -265,5 +223,5 @@

var command, _ref;
_ref = Util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
command = new CliCommand(['git', 'checkout'], branch, options);
return Runner.execute(command, this._getOptions(), callback);
return execute(command, this._getOptions(), callback);
};

@@ -277,10 +235,24 @@

if (_.isArray(args)) {
_ref = Util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
} else {
_ref1 = [Util.setOptions(args, options), []], (_ref2 = _ref1[0], options = _ref2[0], callback = _ref2[1]), args = _ref1[1];
_ref1 = [util.setOptions(args, options), []], (_ref2 = _ref1[0], options = _ref2[0], callback = _ref2[1]), args = _ref1[1];
}
command = new CliCommand(['git', 'push'], args, options);
return Runner.execute(command, this._getOptions(), callback);
return execute(command, this._getOptions(), callback);
};
Repository.prototype.addRemote = function(name, url, options, callback) {
var command, _ref;
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
command = new CliCommand(['git', 'remote', 'add'], [name, url], options);
return execute(command, this._getOptions(), callback);
};
Repository.prototype.setRemoteUrl = function(name, url, options, callback) {
var command, _ref;
_ref = util.setOptions(options, callback), options = _ref[0], callback = _ref[1];
command = new CliCommand(['git', 'remote', 'set-url'], [name, url], options);
return execute(command, this._getOptions(), callback);
};
Repository.prototype.workingDir = function() {

@@ -287,0 +259,0 @@ return path.dirname(this.path);

(function() {
var S, Util, _;
var S, util, _;

@@ -8,3 +8,3 @@ _ = require('underscore');

Util = {
util = {
hasType: function(object, type) {

@@ -21,3 +21,3 @@ return object.constructor.name === type.name;

type = allowedTypes[_i];
if (valid = Util.hasType(object, type)) {
if (valid = this.hasType(object, type)) {
break;

@@ -70,7 +70,19 @@ }

}
},
wrapCallback: function(callback, handler) {
var done;
if (callback == null) {
return;
}
done = callback;
return function(err, stdout, stderr) {
var args;
args = handler(err, stdout, stderr);
return done(err, args);
};
}
};
module.exports = Util;
module.exports = util;
}).call(this);
{
"name": "git-cli",
"version": "0.6.2",
"version": "0.7.0",
"description": "Simple CLI like git interface for NodeJS",

@@ -5,0 +5,0 @@ "main": "lib/git-cli.js",

@@ -19,4 +19,34 @@ # node-git-cli [![Build Status][travis-img]][travis-build] [![Coverage Status][coveralls]][coveralls-img]

The usage is pretty straightforward, checkout out [the tests](test/repository-test.coffee) for some examples.
The usage is pretty straightforward, here is a sample code.
```coffee
Repository = require('git-cli').Repository
fs = require 'fs'
Repository.clone 'https://github.com/tuvistavie/node-git-cli', 'git-cli', (err, repo) ->
repo.log (err, logs) ->
console.log logs[0].subject
repo.showRemote 'origin', (err, remote) ->
console.log remote.fetchUrl
fs.writeFileSync "#{repo.workingDir()}/newFile", 'foobar'
repo.status (err, status) ->
console.log status[0].path
console.log status[0].tracked
repo.add (err) ->
repo.status (err, status) ->
console.log status[0].path
console.log status[0].tracked
repo.commit 'added newFile', (err) ->
repo.log (err, logs) ->
console.log logs[0].subject
repo.push (err) ->
console.log 'pushed to remote'
```
Checkout out [the tests](test/repository-test.coffee) for more examples.
[travis-build]: https://travis-ci.org/tuvistavie/node-git-cli

@@ -23,0 +53,0 @@ [travis-img]: https://travis-ci.org/tuvistavie/node-git-cli.svg?branch=master

Sorry, the diff of this file is too big to display