forked from danielmahon/gift
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic support for reading git config
- Loading branch information
Eric O'Connell
committed
Oct 5, 2013
1 parent
9503fc8
commit 9ef8c80
Showing
5 changed files
with
75 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
should = require 'should' | ||
Config = require '../src/config' | ||
|
||
GIT_CONFIG = """ | ||
user.name=John Doe | ||
[email protected] | ||
core.editor=pico | ||
""" | ||
|
||
GIT_CONFIG_DUPLICATE_KEYS = """ | ||
user.name=John Doe | ||
[email protected] | ||
core.editor=pico | ||
[email protected] | ||
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 '[email protected]' | ||
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 '[email protected]' | ||
config.values['core.editor'].should.equal 'emacs' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters