Skip to content

Commit

Permalink
use ini instead of iniparser
Browse files Browse the repository at this point in the history
unit test added for duplicate user section issue

close eugeneware#6
  • Loading branch information
zkochan committed Mar 28, 2016
1 parent 5d735aa commit 1ef59c1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
var parser = require('iniparser'),
path = require('path');
var ini = require('ini'),
path = require('path'),
fs = require('fs');

module.exports = function (gitConfigPath, cb) {
if (typeof cb === 'undefined') {
cb = gitConfigPath;
gitConfigPath = path.join(
process.env.HOME || process.env.USERPROFILE, '.gitconfig');
}
parser.parse(gitConfigPath, cb);
fs.readFile(gitConfigPath, 'utf-8', function (err, iniContent) {
if (err) {
return cb(err)
}
cb(null, ini.parse(iniContent))
})
};

module.exports.sync = function (gitConfigPath) {
Expand All @@ -17,7 +23,7 @@ module.exports.sync = function (gitConfigPath) {
}
var results = {};
try {
results = parser.parseSync(gitConfigPath);
results = ini.parse(fs.readFileSync(gitConfigPath, 'utf-8'));
} catch (err) { }
return results;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "Eugene Ware <eugene@noblesamurai.com>",
"license": "BSD-3-Clause",
"dependencies": {
"iniparser": "~1.0.5"
"ini": "^1.3.4"
},
"devDependencies": {
"expect.js": "^0.3.1",
Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/gitconfig4.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[color]
diff = auto
status = auto
branch = auto
[gui]
fontdiff = -family \"Lucida Console\" -size 11 -weight normal -slant roman -underline 0 -overstrike 0
[user]
name = Eugene Ware
[user]
email = eugene@noblesamurai.com
[branch]
autosetuprebase = always
[push]
default = tracking
[github]
user = eugeneware
token = notthistoken
10 changes: 10 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,14 @@ describe('git-config', function() {
done();
});
});

it('should be able to parse a .gitconfig file with duplicate user sections', function(done) {
gitConfig(fixturePath('gitconfig4.ini'), function (err, config) {
if (err) return done(err);
expect(config.user.name).to.equal('Eugene Ware');
expect(config.user.email).to.equal('eugene@noblesamurai.com');
expect(config.github.user).to.equal('eugeneware');
done();
});
});
});

0 comments on commit 1ef59c1

Please sign in to comment.