Git client on nodejs
This package is in development and is very unstable as this point.
Branch | Build status |
---|---|
master | |
develop |
This package uses the git CLI. You must to have it installed on your machine to use this module. Go here to download it.
This package is meant to be used by other nodejs applications and it's published on NPM
$ npm install gitcapsule
- Basic support to the git status command.
This example shows a basic flow using gitcapsule
const gitCapsule = require("gitcapsule");
var repositoryOptions = {
"prepareBasePath": true
}
var gitRepository = gitCapsule.createGitRepository("/repo/testAll", repositoryOptions)
gitRepository.on("cloned", function (data) {
var latestCommit = "";
gitRepository.fetch(function (error, data) {
if (error !== null) {
console.error(error.toString());
process.abort();
}
gitRepository.checkout("develop");
});
});
gitRepository.on("checkedout", function (data) {
gitRepository.pull(function (error, data) {
if (error !== null) {
console.error(error.toString());
process.abort();
}
gitRepository.getLatestCommit(function (error, data) {
if (error !== null) {
console.error(error.toString());
process.abort();
}
latestCommit = data.commit;
console.log("Latest commit: " + latestCommit);
process.exit();
})
});
});
gitRepository.on("error", function (error) {
console.error(error.toString());
});
gitRepository.clone("https://github.com/jmtvms/GitCapsule.git");
Those are the available events on the GitRepository. Those events may be used in place of the callback functions, since those are optional.
- error - When a error occurs on any command.
- cloned - When the clone(sting, Function(error, cloneResponse)) function is sucessfuly executed.
- fetched - When the fetch(Function(error, fetchResponse)) function is sucessfuly executed.
- pulled - When the pull(Function(error, pullResponse)) function is sucessfuly executed.
- gotLatestCommit - When the getLatestCommit(Function(error, latestCommitResponse)) function is sucessfuly executed.
- checkedOut - When the checkout(sting, Function(error, checkoutResponse)) function is sucessfuly executed.
- gotStatus - When the status(Function(error, statusResponse)) function is sucessfuly executed.
Those responses are passes on the callback or event functions
- baseResponse - All responses derive from this response and have this fieds available.
- The responses cloneResponse, fetchResponse and checkoutResponse are exactly equal to baseResponse.
{
raw: string; //The raw output from the git CLI
lines: string[]; //The output from the git CLI splited in lines.
}
- pullResponse
{
//...baseResponse fields...
alreadyUpToDate: boolean; //If the local repository is already up to date with the remote.
}
- latestCommitResponse
{
//...baseResponse fields...
commit: string; //The hash that identify the HEAD commit.
}
- statusResponse
{
//...baseResponse fields...
isRepository: boolean; //If the folder is a git repository.
}
To contribute to this package, just ask us or create a pull request.