0.11.0 • Published 6 years ago

git-cli v0.11.0

Weekly downloads
66
License
MIT
Repository
github
Last release
6 years ago

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.

0.11.0

6 years ago

0.10.0

8 years ago

0.9.1

8 years ago

0.9.0

8 years ago

0.8.3

9 years ago

0.8.2

10 years ago

0.8.1

10 years ago

0.8.0

10 years ago

0.7.0

10 years ago

0.6.2

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago