mirror of
https://github.com/danog/gift.git
synced 2024-12-02 09:17:55 +01:00
Add basic support for reading git config
This commit is contained in:
parent
9503fc8208
commit
9ef8c80096
17
src/config.coffee
Normal file
17
src/config.coffee
Normal 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)->
|
||||||
|
@values = {}
|
||||||
|
for line in text.split("\n")
|
||||||
|
if line.length == 0
|
||||||
|
continue
|
||||||
|
[key, value] = line.split('=')
|
||||||
|
@values[key] = value
|
@ -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
36
test/config.test.coffee
Normal 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.values['user.name'].should.equal 'John Doe'
|
||||||
|
config.values['user.email'].should.equal 'john.doe@git-scm.com'
|
||||||
|
config.values['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.values['user.name'].should.equal 'John Doe'
|
||||||
|
config.values['user.email'].should.equal 'john.doe@github.com'
|
||||||
|
config.values['core.editor'].should.equal 'emacs'
|
Loading…
Reference in New Issue
Block a user