Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.1 #4

Merged
merged 11 commits into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ $ gituser -h

Commands:

add [options] <user> <name> [email] add user configuration
remove|rm <user> remove user configuration
list|ls list user configuration
set [options] <user> set local git user configuration from <user>
unset unset local git user configuration
add|save [options] <user> <name> [email] save the specified user configuration information
remove|rm <user> delete the specified user configuration information
list|ls list all user configuration information
set [options] <user> set local git config user from <user> configuration information
unset unset local git config user

Easily switch git users.

Expand Down
11 changes: 6 additions & 5 deletions bin/gituser.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ program

program
.command('add <user> <name> [email]')
.description('add user configuration')
.alias('save')
.description('save the specified user configuration information')
.option('--private-github', 'private email address for GitHub', null, null)
.action((user, name, email, options) => {
noArgs = false
Expand All @@ -45,7 +46,7 @@ program
program
.command('remove <user>')
.alias('rm')
.description('remove user configuration')
.description('delete the specified user configuration information')
.action((user, options) => {
noArgs = false

Expand All @@ -61,7 +62,7 @@ program
program
.command('list')
.alias('ls')
.description('list user configuration')
.description('list all user configuration information')
.action((options) => {
noArgs = false

Expand All @@ -76,7 +77,7 @@ program

program
.command('set <user>')
.description('set local git user configuration from <user>')
.description('set local git config user from <user> configuration information')
.option('--private-github', 'private email address for GitHub', null, null)
.action((user, options) => {
noArgs = false
Expand All @@ -92,7 +93,7 @@ program

program
.command('unset')
.description('unset local git user configuration')
.description('unset local git config user')
.action((options) => {
noArgs = false

Expand Down
14 changes: 8 additions & 6 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,28 @@ function init (dir, file) {
let stat
try {
stat = fs.statSync(dir)
// fs.accessSync(dir)
} catch (e) {
stat = null
}
if (stat) {
if (!stat.isDirectory()) throw new ReferenceError('Can not create config directory')
} else {
if (!stat) {
fs.mkdirSync(dir, 0o777)
} else if (!stat.isDirectory()) {
throw new ReferenceError('Can not create config directory')
}

// config file
file = path.join(dir, file)
try {
stat = fs.statSync(file)
// fs.accessSync(dir)
} catch (e) {
stat = null
}
if (stat) {
if (!stat.isFile()) throw new ReferenceError('Can not create config file')
} else {
if (!stat) {
fs.writeFileSync(file, JSON.stringify(defaultData))
} else if (!stat.isFile()) {
throw new ReferenceError('Can not create config file')
}

return file
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gituser",
"version": "1.0.0",
"version": "1.0.1",
"description": "Easily switch git users.",
"preferGlobal": true,
"main": "index.js",
Expand Down
43 changes: 40 additions & 3 deletions test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
const os = require('os')
const path = require('path')
const fs = require('fs')

const test = require('ava')

Expand All @@ -14,8 +15,26 @@ const fileName = 'config.test'
const {init, write, read} = require('../lib/config').base
const {writeDefault, writeAllDefault, readDefault} = require('../lib/config')

const _init = require('../lib/init')

test.serial('init pass', t => {
try {
_init()
t.pass()
} catch (e) {
t.fail(e)
}
})

test.serial('config init', t => {
try {
fs.unlinkSync(path.join(dir, fileName))
} catch (e) {
}
t.pass()
})

test.serial('config init pass', t => {
console.log(__dirname)
try {
init(dir, fileName)
t.pass()
Expand All @@ -33,7 +52,25 @@ test.serial('config init fail', t => {
}
})

test.serial('config write pass', t => {
test.serial('config write pass1', t => {
try {
let file = write(dir, fileName, null)
t.true(!!file)
} catch (e) {
t.fail(e)
}
})

test.serial('config read fail', t => {
try {
let obj = read(dir, fileName)
t.false(!!obj)
} catch (e) {
t.fail(e)
}
})

test.serial('config write pass2', t => {
try {
let file = write(dir, fileName, {
'version': pkg.version,
Expand All @@ -49,7 +86,7 @@ test.serial('config write pass', t => {
}
})

test.serial('config read pass', t => {
test.serial('config read pass2', t => {
try {
let obj = read(dir, fileName)
t.true(!!obj)
Expand Down
16 changes: 0 additions & 16 deletions test/init.test.js

This file was deleted.