
Security News
npm Tooling Bug Incorrectly Marks One-Character Packages as Security Holders
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.
nodegit-kit
Advanced tools
Complementary NodeGit helpers returning native Promises, helps with git commands such as init, add, commit, status, diff
Promises for git commands such as git init,
git status, git add *, git diff, git log and git commit -am"commit message".
Comments are welcome at nodegit-kit/issues
npm i --save nodegit-kit
var git = require('nodegit-kit');
git.open('../repo-path/new/or/existing')
.then(function(repo){
// git diff
return git.diff(repo)
.then(function(diff){
console.log(diff);
// git commit -am"commit message"
return git.commit(repo, {
'message': 'commit message'
});
})
.then(function(){
// git log
return git.log(repo);
})
.then(function(log){
console.log(log);
});
})
.catch(function(error){
console.error(error);
});
Returns repository, if no repo is found, tries to create the directory and initializes the repository. Initializing is using init internally.
path Stringoptions Object
init Boolean whether to create a first commit, defaults to truegit.open('../repo-path/new/or/existing', {
'init': false
})
.then(function(repo){
// NodeGit repository instance
})
.catch(function(){
// no repo here
});
Checks if status has pending changes, commits, returns Oid else returns null.
repo NodeGit repository instanceoptions
message String defaults to 'update'git.open('../repo-path/new/or/existing')
.then(function(repo){
// git commit -am"a new commit"
return git.commit(repo, {
'message': 'a new commit'
})
.then(function(oid){
console.log(oid);
});
});
Returns an Array of changed files and their status.
repo NodeGit repository instancegit.open('../repo-path/new/or/existing')
.then(function(repo){
// git status
return git.status(repo)
.then(function(status){
console.log(status);
});
});
Returns an Array of all commits.
repo NodeGit repository instanceoptions
branch String name of a branch, defaults to 'master'sort String can be 'none', 'topological', 'time' or 'reverse'abbrev-commit Boolean if true shortens checksum, defaults to falseabbrev Number to specify a custom number of digits in combination with abbrev-commit, otherwise uses 'core.abbrev' configgit.open('../repo-path/new/or/existing')
.then(function(repo){
// git log
return git.log(repo)
.then(function(log){
console.log(log);
});
});
Returns an Array of modified files and their diffs.
repo NodeGit repository instancegit.open('../repo-path/new/or/existing')
.then(function(repo){
// git diff
return git.diff(repo)
.then(function(diff){
console.log(diff);
});
});
git.open('../repo-path/new/or/existing')
.then(function(repo){
return git.log(repo)
.then(function(history){
return history[0].commit;
})
.then(function(commit){
// git diff <commit>
return git.diff(repo, commit);
})
.then(function(diff){
console.log(diff);
});
});
Breaking API change in 0.12.0
Changed order of from and to to be aligned with git-cli.
git.open('../repo-path/new/or/existing')
.then(function(repo){
return git.log(repo, { sort: 'reverse' })
.then(function(history){
var commit1 = history[0].commit;
var commit2 = history[2].commit;
// git diff <from> <to>
return git.diff(repo, commit1, commit2);
})
.then(function(diff){
console.log(diff);
});
});
Allows to write/read global and local git config values.
Local values are stored in the Git directory ./git/config and overrule global configurations.
Note: Git locks the config when changing configurations,
therefore writing multiple configs can not be done in parallel.
e.g. Promise.all multiple individual git.config.set calls
will throw a "Failed to lock file for writing" error,
nodegit/issues/757.
See also 8.1 Customizing Git - Git Configuration (Git SCM Documentation)
Set user name and email similar to cd repo then
git config user.name "John Doe" and git config user.email johndoe@example.com.
git.open('my/repository')
.then(function(repo){
return git.config.set(repo, {
'user.name': 'John Doe',
'user.email': 'johndoe@example.com'
});
});
Similar to cd repo thengit config user.name returns config for a repository if there any or else the global Git configuration.
git.open('my/repository')
.then(function(repo){
return git.config.get(repo, ['user.name', 'user.email']);
})
.then(function(configs){
// [ 'John Doe', 'johndoe@example.com' ]
});
When no repo is given, setting and getting config will operate in --global mode and read and write to ~/.gitconfig (or ~/.config/git/config).
git.config.get(['user.name', 'user.email'])
.then(function(config){
// [ 'John Doe', 'johndoe@example.com' ]
});
// WARNING: this will change your global git config
git.config.set({
'user.name': 'John Doe',
'user.email': 'johndoe@example.com'
});
Ensures directory exists, initializes, creates a first commit and returns repo. This is optional and only useful to control the first commit.
path Stringoptions Object
bare Number defaults to 0commit Boolean defaults to truemessage String defaults to 'initial commit'git.init('../repo-path/new/or/existing', {
'bare': 0,
'commit': true,
'message': 'my first commit'
})
.then(function(repo){
// NodeGit repository instance
});
Can be used to in combination with suppressing commit on init.
repo NodeGit Repository instanceoptions
message String defaults to 'initial commit'git.open('../path/to/repo', {
'init': false
})
.catch(function(){
return git.init('../path/to/repo', {
'commit': false
})
.then(function(repo){
// do something before first commit
return repo;
})
.then(function(repo){
git.init.commit(repo, {
'message': 'initialize repository'
});
});
})
.then(function(repo){
// NodeGit repository instance
});
npm install
npm test
# debug nodegit-kit
DEBUG=kit* npm test
# debug all
DEBUG=* npm test
FAQs
Complementary NodeGit helpers returning native Promises, helps with git commands such as init, add, commit, status, diff
The npm package nodegit-kit receives a total of 385 weekly downloads. As such, nodegit-kit popularity was classified as not popular.
We found that nodegit-kit 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
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.

Research
/Security News
Newer packages in this compromise use native extensions and .pth loaders to execute JavaScript stealers in developer environments.

Research
Socket found 37 malicious PyPI wheels that abuse Python startup hooks to launch a Bun-powered credential stealer tied to Mini Shai-Hulud/Miasma.