0.0.8 • Published 6 years ago

git-command-cli v0.0.8

Weekly downloads
1
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))

fork from https://github.com/tuvistavie/node-git-cli

原始例子比较简单,可以看看test下面的测试用例,很详细
加入fetch,暴露了命令接口

Checkout out the tests for more examples.

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago