1
0
mirror of https://github.com/danog/gift.git synced 2024-11-26 20:04:47 +01:00

Merge branch 'master' of github.com:sentientwaffle/gift

* 'master' of github.com:sentientwaffle/gift:
  rename values to items
  Update docs
  Config, not Status
  update README
  Add basic support for reading git config
  updated diff regex
This commit is contained in:
Luke Plaster 2013-10-12 15:42:38 +02:00
commit 6dc6ce3879
7 changed files with 83 additions and 21 deletions

View File

@ -120,6 +120,9 @@ Remove a remote.
### `Repo#status(callback)` ### `Repo#status(callback)`
Uses `--porcelain` to parse repository status in a way that is agnostic of system language. The callback receives `(err, status)`. See below for a definition of what `status` is. Uses `--porcelain` to parse repository status in a way that is agnostic of system language. The callback receives `(err, status)`. See below for a definition of what `status` is.
### `Repo#config(callback)`
`git config` parsed as a simple, one-level object. The callback receives `(err, config)`.
### `Repo#create_branch(name, callback)` ### `Repo#create_branch(name, callback)`
Create a new branch with `name`, and call the callback when complete Create a new branch with `name`, and call the callback when complete
with an error, if one occurred. with an error, if one occurred.
@ -227,6 +230,10 @@ The callback receives `(err, actor)`.
### `Tag#tag_date(callback)` ### `Tag#tag_date(callback)`
The callback receives `(err, date)`. The callback receives `(err, date)`.
## Config
### `Config#items`
`Object` - The keys are dotted precisely as the console output from `git config`. E.g., `{'user.name': 'John Doe'}`
## Status ## Status
### `Status#clean` ### `Status#clean`
`Boolean` `Boolean`
@ -304,5 +311,3 @@ Get the url the submodule points to.
# License # License
See LICENSE. See LICENSE.

17
src/config.coffee Normal file
View File

@ -0,0 +1,17 @@
module.exports = C = (repo, callback) ->
repo.git "config", {list: true}, (err, stdout, stderr) ->
config = new Config repo
config.parse stdout
callback err, config
C.Config = class Config
constructor: (@repo) ->
# Internal: Parse the config from stdout of a `git config` command
parse: (text)->
@items = {}
for line in text.split("\n")
if line.length == 0
continue
[key, value] = line.split('=')
@items[key] = value

View File

@ -22,7 +22,7 @@ module.exports = class Diff
diffs = [] diffs = []
while lines.length && lines[0] while lines.length && lines[0]
[m, a_path, b_path] = ///^diff\s--git\sa/(.+?)\sb/(.+)$///.exec lines.shift() [m, a_path, b_path] = ///^diff\s--git\s"?a/(.+?)"?\s"?b/(.+)"?$///.exec lines.shift()
if /^old mode/.test lines[0] if /^old mode/.test lines[0]
[m, a_mode] = /^old mode (\d+)/.exec lines.shift() [m, a_mode] = /^old mode (\d+)/.exec lines.shift()

View File

@ -2,6 +2,7 @@ _ = require 'underscore'
cmd = require './git' cmd = require './git'
Actor = require './actor' Actor = require './actor'
Commit = require './commit' Commit = require './commit'
Config = require './config'
Tree = require './tree' Tree = require './tree'
Diff = require './diff' Diff = require './diff'
Tag = require './tag' Tag = require './tag'
@ -184,6 +185,9 @@ module.exports = class Repo
status: (callback) -> status: (callback) ->
return Status(this, callback) return Status(this, callback)
config: (callback) ->
return Config(this, callback)
# Public: Get the repository's tags. # Public: Get the repository's tags.
# #

36
test/config.test.coffee Normal file
View File

@ -0,0 +1,36 @@
should = require 'should'
Config = require '../src/config'
GIT_CONFIG = """
user.name=John Doe
user.email=john.doe@git-scm.com
core.editor=pico
"""
GIT_CONFIG_DUPLICATE_KEYS = """
user.name=John Doe
user.email=john.doe@git-scm.com
core.editor=pico
user.email=john.doe@github.com
core.editor=emacs
"""
describe "Config", ->
describe "()", ->
describe "when there are no overlapping keys", ->
config = new Config.Config 'mock repo'
config.parse GIT_CONFIG
it "read the keys and values", ->
config.items['user.name'].should.equal 'John Doe'
config.items['user.email'].should.equal 'john.doe@git-scm.com'
config.items['core.editor'].should.equal 'pico'
describe "with overlapping keys", ->
config = new Config.Config 'mock repo'
config.parse GIT_CONFIG_DUPLICATE_KEYS
it "read the keys and values", ->
config.items['user.name'].should.equal 'John Doe'
config.items['user.email'].should.equal 'john.doe@github.com'
config.items['core.editor'].should.equal 'emacs'