git-cli

0.11.0 • Public • Published

node-git-cli Build Status Coverage Status

A simple git interface for NodeJS. It is not intended to replace projects such as 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.

Repository = require('git-cli').Repository
fs = require 'fs'
 
Repository.clone 'https://github.com/tuvistavie/node-git-cli''git-cli'(err, repo) ->
  repo.log (err, logs) ->
    console.log logs[0].subject
    repo.showRemote 'origin'(err, remote) ->
      console.log remote.fetchUrl
 
      fs.writeFileSync "#{repo.workingDir()}/newFile"'foobar'
      repo.status (err, status) ->
        console.log status[0].path
        console.log status[0].tracked
 
        repo.add (err) ->
          repo.status (err, status) ->
            console.log status[0].path
            console.log status[0].tracked
 
            repo.commit 'added newFile'(err) ->
              repo.log (err, logs) ->
                console.log logs[0].subject
 
              repo.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:

const Repository = require('git-cli').Repository
const fs = require('fs')
 
Repository.clone('https://github.com/tuvistavie/node-git-cli', '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 for more examples.

Readme

Keywords

Package Sidebar

Install

npm i git-cli

Weekly Downloads

62

Version

0.11.0

License

MIT

Unpacked Size

28.9 kB

Total Files

19

Last publish

Collaborators

  • danhper