New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

impromptu-git

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

impromptu-git - npm Package Compare versions

Comparing version

to
0.2.0-beta.0

583

index.js

@@ -1,303 +0,358 @@

// Generated by CoffeeScript 1.6.2
(function() {
var fs, getStatuses, path;
var impromptu = require('impromptu')
var fs = require('fs')
var path = require('path')
fs = require('fs');
// Helper function to format git statuses
var getStatuses = function (porcelainStatus) {
var PORCELAIN_PROPERTY_REGEXES = {
// Leading non-whitespace that is not a question mark
staged: /^[^\?\s]/,
// Trailing non-whitespace
unstaged: /\S$/,
// Any "A" or "??"
added: /A|\?\?/,
// Any "M"
modified: /M/,
// Any "D"
deleted: /D/,
// Any "R"
renamed: /R/
}
path = require('path');
return porcelainStatus.replace(/\s+$/, '').split('\0').map(function(line) {
var status = line.substring(0, 2)
var properties = []
for (var property in PORCELAIN_PROPERTY_REGEXES) {
if (PORCELAIN_PROPERTY_REGEXES[property].test(status)) properties.push(property)
}
getStatuses = function(porcelainStatus) {
var PORCELAIN;
return {
path: line.slice(3),
properties: properties
}
})
}
PORCELAIN = {
staged: /^[^\?\s]/,
unstaged: /\S$/,
added: /A|\?\?/,
modified: /M/,
deleted: /D/
};
return porcelainStatus.replace(/\s+$/, '').split('\0').map(function(line) {
var prop, regex, status;
module.exports = impromptu.plugin.create(function(git) {
// Helper to figure out if we're in a repo at all
git.register('isRepo', {
update: function(done) {
var command = '([ -d .git ] || [[ "true" == `git rev-parse --is-inside-work-tree 2>&1` ]])'
impromptu.exec(command, function(err) {
done(err, !err)
})
}
})
status = line.substring(0, 2);
return {
path: line.slice(3),
properties: (function() {
var _results;
// Root path to the repository
git.register('root', {
update: function(done) {
var command = 'git rev-parse --show-toplevel 2>/dev/null'
impromptu.exec(command, function(err, result) {
if (err) {
done(err, null)
} else {
done(err, result.trim())
}
})
}
})
_results = [];
for (prop in PORCELAIN) {
regex = PORCELAIN[prop];
if (regex.test(status)) {
_results.push(prop);
}
}
return _results;
})()
};
});
};
// Branch name
// Returns commit hash when head is detached
// Returns null in newly-initialized repos (note that isRepo() still returns true in this case)
git.register('branch', {
update: function(done) {
var command = 'git rev-parse --abbrev-ref HEAD 2>/dev/null'
impromptu.exec(command, function(err, result) {
if (err) {
done(err, null)
return
}
module.exports = function(Impromptu, register, git) {
var Statuses;
result = result.trim()
if (result !== 'HEAD') {
done(err, result)
return
}
register('isRepo', {
update: function(done) {
var command;
impromptu.exec('git rev-parse --short HEAD', function(_err, _result) {
done(_err, _result)
})
})
}
})
command = '([ -d .git ] || [[ "true" == `git rev-parse --is-inside-work-tree 2>&1` ]])';
return Impromptu.exec(command, function(err) {
return done(err, !err);
});
}
});
register('root', {
update: function(done) {
var command;
// Short commit hash
git.register('commit', {
update: function(done) {
impromptu.exec('git rev-parse --short HEAD 2>/dev/null', function(err, result) {
if (err) {
done(err, null)
} else {
done(err, result.trim())
}
})
}
})
command = 'git rev-parse --show-toplevel 2>/dev/null';
return Impromptu.exec(command, function(err, result) {
if (err) {
return done(err, null);
} else {
return done(err, result.trim());
}
});
}
});
register('branch', {
update: function(done) {
var command;
// Determine whether the repo is currently in a detached head state
// This happens when you checkout, for example, a commit hash
git.register('isDetachedHead', {
update: function(done) {
impromptu.exec('git symbolic-ref HEAD 2>/dev/null', function(err) {
done(err, !!err)
})
}
})
command = 'git rev-parse --abbrev-ref HEAD 2>/dev/null';
return Impromptu.exec(command, function(err, result) {
if (err) {
return done(err, null);
}
result = result.trim();
if (result !== 'HEAD') {
return done(err, result);
}
return Impromptu.exec('git rev-parse --short HEAD', function(_err, _result) {
return done(_err, _result);
});
});
}
});
register('commit', {
update: function(done) {
return Impromptu.exec('git rev-parse --short HEAD 2>/dev/null', function(err, result) {
if (err) {
return done(err, null);
} else {
return done(err, result.trim());
}
});
}
});
register('isDetachedHead', {
update: function(done) {
return Impromptu.exec('git symbolic-ref HEAD 2>/dev/null', function(err) {
return done(err, !!err);
});
}
});
register('remoteBranch', {
update: function(done) {
var tracking_branch_command;
// Whether the git repository is in the middle of a rebase.
git.register('isRebasing', {
update: function(done) {
git.root(function(err, root) {
if (err) {
done(err)
return
}
tracking_branch_command = "git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)";
return Impromptu.exec(tracking_branch_command, function(err, result) {
if (result) {
return done(err, result.trim());
var command = "test -d " + root + "/.git/rebase-merge -o -d " + root + "/.git/rebase-apply"
impromptu.exec(command, function(err) {
if (!err) {
done(null, true)
} else if (err.code === 1) {
done(null, false)
} else {
return done(err, null);
done(err, null)
}
});
}
});
register('_aheadBehind', {
update: function(done) {
return git.remoteBranch(function(err, remoteBranch) {
var command;
})
})
}
})
// The remote branch name, if it exists
git.register('remoteBranch', {
update: function(done) {
var trackingBranchCommand = "git for-each-ref --format='%(upstream:short)'" +
" $(git symbolic-ref -q HEAD)"
impromptu.exec(trackingBranchCommand, function(err, result) {
if (result) {
done(err, result.trim())
} else {
done(err, null)
}
})
}
})
// Returns an object with 'ahead' and 'behind' keys
// Each has a count of commits that your repo is ahead/behind its upstream
//
// This command *must* be passed through a formatter before its displayed
git.register('_aheadBehind', {
update: function(done) {
git.fetch(function(err) {
if (err) {
done(err, null)
return
}
git.remoteBranch(function(err, remoteBranch) {
if (!remoteBranch) {
return done(err, null);
done(err, null)
return
}
command = "git rev-list --left-right --count " + (remoteBranch.trim()) + "...HEAD";
return Impromptu.exec(command, function(err, result) {
var data;
var command = "git rev-list --left-right --count " + (remoteBranch.trim()) + "...HEAD"
impromptu.exec(command, function(err, result) {
if (err) {
return done(err, null);
done(err, null)
return
}
data = result.trim().split(/\s+/).map(function(value) {
return parseInt(value, 10);
});
return done(err, {
var data = result.trim().split(/\s+/).map(function(value) {
return parseInt(value, 10)
})
done(err, {
behind: data[0],
ahead: data[1]
});
});
});
})
})
})
})
}
})
// Get the number of commits you're ahead of the remote
git.register('ahead', {
update: function(done) {
git._aheadBehind(function(err, aheadBehind) {
done(err, aheadBehind != null ? aheadBehind.ahead : void 0)
})
}
})
// Get the number of commits you're behind the remote
git.register('behind', {
update: function(done) {
git._aheadBehind(function(err, aheadBehind) {
done(err, aheadBehind != null ? aheadBehind.behind : void 0)
})
}
})
var Statuses = function (statuses) {
this.statuses = statuses
var properties = ['added', 'modified', 'deleted', 'renamed', 'staged', 'unstaged']
var property = null
// Create status arrays.
for (var i = 0; i < properties.length; i++) {
this[properties[i]] = []
}
// Bind array formatters.
for (property in Statuses.formatters) {
if (this[property]) {
this[property].toString = Statuses.formatters[property]
}
});
register('ahead', {
update: function(done) {
return git._aheadBehind(function(err, aheadBehind) {
return done(err, aheadBehind != null ? aheadBehind.ahead : void 0);
});
}
});
register('behind', {
update: function(done) {
return git._aheadBehind(function(err, aheadBehind) {
return done(err, aheadBehind != null ? aheadBehind.behind : void 0);
});
}
});
Statuses = (function() {
function Statuses(statuses) {
var formatter, properties, property, status, _i, _j, _k, _len, _len1, _len2, _ref, _ref1;
}
this.statuses = statuses;
properties = ['added', 'modified', 'deleted', 'staged', 'unstaged'];
for (_i = 0, _len = properties.length; _i < _len; _i++) {
property = properties[_i];
this[property] = [];
// Populate status arrays.
for (var j = 0; j < this.statuses.length; j++) {
var status = this.statuses[j]
for (var k = 0; k < properties.length; k++) {
property = properties[k]
if (status.properties.indexOf(property) > -1) {
this[property].push(status)
}
_ref = Statuses.formatters;
for (property in _ref) {
formatter = _ref[property];
if (this[property]) {
this[property].toString = formatter;
}
}
_ref1 = this.statuses;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
status = _ref1[_j];
for (_k = 0, _len2 = properties.length; _k < _len2; _k++) {
property = properties[_k];
if (status.properties.indexOf(property) > -1) {
this[property].push(status);
}
}
}
}
}
}
Statuses.prototype.toString = function() {
var results;
Statuses.prototype.toString = function() {
var results = []
if (this.modified.length) results.push(this.modified)
if (this.added.length) results.push(this.added)
if (this.deleted.length) results.push(this.deleted)
if (this.renamed.length) results.push(this.renamed)
return results.join(' ')
}
results = [];
if (this.modified.length) {
results.push(this.modified);
}
if (this.added.length) {
results.push(this.added);
}
if (this.deleted.length) {
results.push(this.deleted);
}
return results.join(' ');
};
Statuses.formatters = {
added: function() {
return this.length ? '+' + this.length : ''
},
modified: function() {
return this.length ? '∆' + this.length : ''
},
deleted: function() {
return this.length ? '-' + this.length : ''
},
renamed: function() {
return this.length ? '→' + this.length : ''
}
}
Statuses.formatters = {
added: function() {
if (this.length) {
return "+" + this.length;
} else {
return "";
}
},
modified: function() {
if (this.length) {
return "∆" + this.length;
} else {
return "";
}
},
deleted: function() {
if (this.length) {
return "-" + this.length;
} else {
return "";
}
// Returns an array of objects with 'path', 'code', 'staged', 'state'
//
// This command *must* be passed through a formatter before its displayed
git.register('_status', {
update: function(done) {
impromptu.exec('git status --porcelain -z 2>/dev/null', function(err, result) {
if (err) {
done(err, null)
return
}
};
return Statuses;
var statuses = getStatuses(result)
done(null, new Statuses(statuses))
})
}
})
})();
register('_status', {
// Register object and string methods for filtering the statuses.
//
// Object methods: `_staged`, `_unstaged`, `_added`, `_modified`, `_deleted`, `_renamed`
// String methods: `staged`, `unstaged`, `added`, `modified`, `deleted`, `renamed`
//
// Strings are formatted as "∆2 +1 -3" by default.
;['staged', 'unstaged', 'added', 'modified', 'deleted', 'renamed'].forEach(function(type) {
// Get an object that has filtered the statuses by type.
git.register("_" + type, {
update: function(done) {
return Impromptu.exec('git status --porcelain -z 2>/dev/null', function(err, result) {
var statuses;
git._status(function(err, statuses) {
done(err, new Statuses(statuses[type]))
})
}
})
if (err) {
return done(err, null);
}
statuses = getStatuses(result);
return done(null, new Statuses(statuses));
});
// Get a string that represents the status.
// Format: "∆2 +1 -3 →2"
git.register(type, {
update: function(done) {
git["_" + type](function(err, statuses) {
done(err, statuses.toString())
})
}
});
['staged', 'unstaged', 'added', 'modified', 'deleted'].forEach(function(type) {
register("_" + type, {
update: function(done) {
return git._status(function(err, statuses) {
return done(err, new Statuses(statuses[type]));
});
})
})
// Fetch information about the repository
git.register('fetch', {
cache: 'repository',
expire: 60,
update: function(done) {
git.isRepo(function(err, isRepo) {
if (!isRepo) {
done(err, isRepo)
return
}
});
return register(type, {
update: function(done) {
return git["_" + type](function(err, statuses) {
return done(err, statuses.toString());
});
impromptu.exec('git fetch --all', function(err, results) {
done(err, results)
})
})
}
})
// Find the number of git stashes
git.register('stashCount', {
update: function(done) {
git.root(function(err, root) {
if (err) {
done(err)
return
}
});
});
register('fetch', {
cache: 'repository',
expire: 60,
update: function(done) {
return git.isRepo(function(err, isRepo) {
if (!isRepo) {
return done(err, isRepo);
fs.exists(path.join(root, '.git/logs/refs/stash'), function(exists) {
if (!exists) {
done(null, 0)
return
}
return Impromptu.exec('git fetch --all', function(err, results) {
return done(err, results);
});
});
}
});
register('stashCount', {
update: function(done) {
return git.root(function(err, root) {
if (err) {
return done(err);
}
return fs.exists(path.join(root, '.git/logs/refs/stash'), function(exists) {
if (!exists) {
return done(null, 0);
}
return Impromptu.exec("wc -l " + (path.join(root, '.git/logs/refs/stash')), function(err, count) {
return done(err, parseInt(count.trim(), 10));
});
});
});
}
});
register('remoteUrl', {
update: function(done) {
return Impromptu.exec('git config --get remote.origin.url', done);
}
});
return this.repository.register('git', {
root: git.root,
branch: git.branch,
commit: git.commit
});
};
}).call(this);
impromptu.exec("wc -l " + (path.join(root, '.git/logs/refs/stash')), function(err, count) {
done(err, parseInt(count.trim(), 10))
})
})
})
}
})
// Find the URL of the origin
git.register('remoteUrl', {
update: function(done) {
impromptu.exec('git config --get remote.origin.url', done)
}
})
// Register the 'git' repository type with impromptu
impromptu.repository.register('git', {
root: git.root,
branch: git.branch,
commit: git.commit
})
})
{
"name": "impromptu-git",
"description": "A git module for Impromptu.",
"version": "0.1.8",
"version": "0.2.0-beta.0",
"homepage": "http://impromptu.sh/",

@@ -25,16 +25,7 @@ "author": "Impromptu Team (http://impromptu.sh/)",

"main": "index.js",
"scripts": {
"prepublish": "cake build",
"test": "mocha test/*.coffee --compilers coffee:coffee-script"
},
"dependencies": {},
"devDependencies": {
"coffee-script": "~1.6.2",
"mocha": "~1.8.2",
"should": "~1.2.2"
},
"peerDependencies": {
"impromptu": "~0.2.0-beta.2"
"impromptu": "~0.3.0-beta.0"
},
"keywords": []
}