Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danhper/node-git-cli
Simple CLI like git interface for Node.
https://github.com/danhper/node-git-cli
Last synced: about 1 month ago
JSON representation
Simple CLI like git interface for Node.
- Host: GitHub
- URL: https://github.com/danhper/node-git-cli
- Owner: danhper
- License: mit
- Created: 2014-05-31T05:55:09.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-10-23T10:40:02.000Z (about 6 years ago)
- Last Synced: 2024-04-15T07:27:22.895Z (8 months ago)
- Language: CoffeeScript
- Homepage: https://www.npmjs.org/package/git-cli
- Size: 73.2 KB
- Stars: 16
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-git-cli [![Build Status][travis-img]][travis-build] [![Coverage Status][coveralls]][coveralls-img]
A simple git interface for NodeJS.
It is not intended to replace projects such as
[nodegit](https://github.com/nodegit/nodegit) but
rather to provide a light weight solution close to
the git command line for simple use cases.## Installation
Just run
```
$ npm install git-cli
```## Usage
The usage is pretty straightforward, here is a sample code.
```coffee
Repository = require('git-cli').Repository
fs = require 'fs'Repository.clone 'https://github.com/danhper/node-git-cli.git', 'git-cli', (err, repo) ->
repo.log (err, logs) ->
console.log logs[0].subject
repo.showRemote 'origin', (err, remote) ->
console.log remote.fetchUrlfs.writeFileSync "#{repo.workingDir()}/newFile", 'foobar'
repo.status (err, status) ->
console.log status[0].path
console.log status[0].trackedrepo.add (err) ->
repo.status (err, status) ->
console.log status[0].path
console.log status[0].trackedrepo.commit 'added newFile', (err) ->
repo.log (err, logs) ->
console.log logs[0].subjectrepo.push (err) ->
console.log 'pushed to remote'
```From version 0.10, all functions still take a callback, but also return promises,
so you can rewrite the above as follow:```javascript
const Repository = require('git-cli').Repository
const fs = require('fs')Repository.clone('https://github.com/danhper/node-git-cli.git', 'git-cli')
.then(repo => {
return repo.log()
.then(logs => {
console.log(logs[0].subject)
return repo.showRemote('origin')
}).then(remote => {
console.log(remote.fetchUrl)
fs.writeFileSync("#{repo.workingDir()}/newFile", 'foobar')
return repo.status()
}).then(status => {
console.log(status[0].path)
console.log(status[0].tracked)
return repo.add()
}).then(() => repo.status())
.then(status => {
console.log status[0].path
console.log status[0].tracked
return repo.commit('added newFile')
}).then(() => repo.log())
.then(logs => {
console.log(logs[0].subject)
return repo.push()
}).then(() => console.log('pushed' to remote))
}).catch(e => console.log(e))
```Checkout out [the tests](test/repository-test.coffee) for more examples.
[travis-build]: https://travis-ci.org/danhper/node-git-cli
[travis-img]: https://travis-ci.org/danhper/node-git-cli.svg?branch=master
[coveralls]: https://coveralls.io/repos/danhper/node-git-cli/badge.png?branch=master
[coveralls-img]: https://coveralls.io/r/danhper/node-git-cli?branch=master