
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
A command builder to build functions that will run git commands and extract output from them in a variety of ways.
git-cmd is a node.js command builder meant to be used to build your own functions to interact with git repositories through the git command.
git-cmd executes the git command with a set of arguments for you, gives you an interface to extract this data, and then returns the result as a Bluebird promise.
$ npm install git-cmd
var git = require('git-cmd');
Construct a git command. The command is not executed at this point.
git command."git"] the path to the git executable.process.cwd] the git directory.This adds a single argument to the args list. This allows you to construct complex conditional commands.
function clone(url, path, opts) {
opts = opts || {};
var cmd = git(['clone']);
if ( opts.bare ) {
cmd.push('--bare');
}
cmd.push(url);
cmd.push(path);
return cmd.pass({prefix: opts.prefix});
}
Add a transform stream to pipe stdout through for the .capture(), .oneline(), and .array() run methods.
var LineStream = require('byline').LineStream;
function tags() {
return git(['tag'], {cwd: cwd})
.pipe(new LineStream())
.array();
}
These commands execute the git command and return the result in various ways.
Execute the command and resolve with a boolean indicating whether the command succeeded (error code=0, true) or failed (error code > 0, false).
stdout and stderr will be ignored.
This result is useful if you're doing a boolean test for the presence of something in the git repository and git exits with an error code when it's missing.
function hasRef(ref) {
return git(['rev-parse', ref], {cwd: cwd}).ok();
}
Execute the command and pass all stdout and stderr output through. The promise is resolved simply with true when the process exits.
This result is useful when running long running commands like fetch and clone that output progress information to the terminal.
""] prefix for every line piped to stdout and stderr.
false] don't pass through stderr output.function fetchOrigin(ref) {
return git(['fetch', 'origin'], {cwd: cwd}).pass();
}
function fetchRepo(name) {
return git(['fetch', 'origin'], {cwd: nameToPath(name)}).pass({prefix: name + ': '});
}
Execute the command and capture the output into a single buffer or string.
Any stderr output is passed through to to the terminal.
This is useful for any command you are capturing binary or multi-line data. Especially raw output such as that from cat-file.
""] prefix for every line piped to stderr.undefined|false) [default=undefined] the character encoding of the data to decode.false] don't pass through stderr output.function catBinaryFile(file) {
return git(['cat-file', 'blob', util.format('HEAD:%s', file)], {cwd: cwd})
.capture();
}
function catTextFile(file) {
return git(['cat-file', 'blob', util.format('HEAD:%s', file)], {cwd: cwd})
.capture({encoding: 'utf8'});
}
Execute the command and capture the output as a string without a trailing line feed.
Any stderr output is passed through to to the terminal.
This is useful for any command that simply returns a simple one-line string.
""] prefix for every line piped to stderr.false] don't pass through stderr output.function getRefHash(ref) {
return git(['show-ref', '--hash', ref], {cwd: suite.cwd})
.oneline();
}
function getSymbolicRef(ref) {
return git(['symbolic-ref', ref], {cwd: cwd})
.oneline();
}
Execute the command and return the result as an array. This method only works when you pipe the output through a transform stream that outputs data in objectMode.
Any stderr output is passed through to to the terminal.
This is useful when you want to return a list of objects processed through transformation streams.
""] prefix for every line piped to stderr.false] don't pass through stderr output.var LineStream = require('byline').LineStream,
es = require('event-stream');
function getRefs() {
return git(['show-ref'], {cwd: cwd})
.pipe(new LineStream())
.pipe(es.mapSync(function(line) {
var m = line.match(/^([0-9a-f]+) (.+)$/);
return {
sha1: m[1],
ref: m[2]
};
}))
.array();
}
function lsTree(treeIsh) {
return git(['ls-tree', treeIsh], {cwd: cwd})
.pipe(new LineStream())
.pipe(es.mapSync(function(line) {
var m = line.match(/^(\d+) ([^ ]+) ([0-9a-f]+)\t(.+)$/);
return {
mode: parseInt(m[1], 10),
type: m[2],
sha1: m[3],
name: m[4]
};
}))
.array();
}
FAQs
A command builder to build functions that will run git commands and extract output from them in a variety of ways.
We found that git-cmd demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.