Skip to content

Commit

Permalink
Merge 4a44071 into db69f1d
Browse files Browse the repository at this point in the history
  • Loading branch information
tcme committed Apr 22, 2017
2 parents db69f1d + 4a44071 commit 73057f5
Show file tree
Hide file tree
Showing 26 changed files with 827 additions and 934 deletions.
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
"git"
],
"scripts": {
"test": "ava --verbose ./test/test-*.js",
"coverage": "nyc npm test",
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
"pretest": "npm run clean && mkdir test/repos",
"test": "tape ./test/*.js | tap-spec",
"coverage": "nyc --reporter=lcov npm test",
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
"clean": "rimraf test/repos"
},
"dependencies": {
"debug": "^2.6.3",
Expand All @@ -31,9 +33,10 @@
},
"license": "MIT",
"devDependencies": {
"ava": "^0.18.2",
"coveralls": "^2.13.0",
"fildes-extra": "^0.6.0",
"nyc": "^10.2.0"
"nyc": "^10.2.0",
"tap-spec": "^4.1.1",
"tape": "^4.6.3"
}
}
2 changes: 1 addition & 1 deletion test/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
repos
repos/*
7 changes: 7 additions & 0 deletions test/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
mkdir repos/commit-git
cd repos/commit-git
git init
echo "Hello\n" > file.txt
# git add .
# git commit -am"first commit"
64 changes: 64 additions & 0 deletions test/commit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const test = require('tape')
const { Oid, Repository } = require('nodegit')
const { resolve } = require('path')
const { writeFile } = require('fildes')

const exec = require('./utils/exec.js')
const git = require('../')


test('commit setup', t => {
Promise.all([
exec('git --version'),
exec('sh commit.sh', { cwd: __dirname })
])
.then(([version, stdout]) => {
t.pass(version)
t.pass(stdout)
t.end()
})
.catch(t.end)
})

test('commit on fresh git repo, missing initial commit', t => {
const path = resolve(__dirname, './repos/commit-git')

git.open(path, { init: false })
.then(repo => {
return git.commit(repo) // TODO: first commit bug?
.catch(error => t.true(error instanceof Error, 'got error'))
.then(() => git.init.commit(repo)) // TODO: :/
.then(oid => {
t.true(oid instanceof Oid, 'is Oid')
return exec('git log', { cwd: path })
.then(stdout => t.true(stdout.includes(oid), 'git log incudes oid'))
})
// commit nothing
.then(() => git.commit(repo, { 'message': 'nothing to commit' }))
.then(oid => t.equal(oid, null, 'no Oid'))
// new file
.then(() => writeFile(resolve(path, 'file2.txt'), 'Hello 2\n'))
.then(() => git.commit(repo, { 'message': 'commits new file' }))
.then(oid => {
t.true(oid instanceof Oid, 'is instance of Oid')
return exec('git log', { cwd: path })
.then(stdout => t.true(stdout.includes(oid), 'git log incudes oid'))
})
// updates file
.then(() => writeFile(resolve(path, 'file.txt'), 'Hello 1\n'))
.then(() => git.commit(repo, { 'message': 'updates file' }))
.then(oid => {
t.true(oid instanceof Oid, 'is instance of Oid')
return exec('git log', { cwd: path })
.then(stdout => t.true(stdout.includes(oid), 'git log incudes oid'))
})
.then(() => exec('git log', { cwd: path }))
.then(stdout => {
t.true(stdout.includes('initial commit'), 'initial commit')
t.true(stdout.includes('commits new file'), 'new file commit message')
t.true(stdout.includes('updates file'), 'update file commit message')
t.end()
})
})
.catch(t.end)
})
5 changes: 5 additions & 0 deletions test/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
mkdir repos/config-git
cd repos/config-git
git init
echo "Hello\n" > file.txt
167 changes: 167 additions & 0 deletions test/config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
const test = require('tape')
const { resolve } = require('path')

const exec = require('./utils/exec.js')
const git = require('../')


// test('config setup', t => {
// exec('sh ./config.sh', { cwd: __dirname })
// .then(stdout => {
// t.pass(stdout)
// t.end()
// })
// .catch(t.end)
// })


test('config should throw lock error when running config.set in parallel', t => {
const path = resolve(__dirname, './repos/config-lock-error')
git.open(path)
.then(repo => {
return Promise.all([
git.config.set(repo, { 'user.name': 'test' }),
git.config.set(repo, { 'user.name': 'test' }),
git.config.set(repo, { 'user.name': 'test' }),
git.config.set(repo, { 'user.name': 'test' }),
git.config.set(repo, { 'user.name': 'test' }),
git.config.set(repo, { 'user.name': 'test' }),
git.config.set(repo, { 'user.name': 'test' }),
git.config.set(repo, { 'user.name': 'test' }),
git.config.set(repo, { 'user.name': 'test' }),
git.config.set(repo, { 'user.name': 'test' }),
git.config.set(repo, { 'user.name': 'test' }),
git.config.set(repo, { 'user.name': 'test' }),
git.config.set(repo, { 'user.email': 'test@localhost' }),
git.config.set(repo, { 'user.email': 'test@localhost' }),
git.config.set(repo, { 'user.email': 'test@localhost' }),
git.config.set(repo, { 'user.email': 'test@localhost' }),
git.config.set(repo, { 'user.email': 'test@localhost' }),
git.config.set(repo, { 'user.email': 'test@localhost' }),
git.config.set(repo, { 'user.email': 'test@localhost' }),
git.config.set(repo, { 'user.email': 'test@localhost' }),
git.config.set(repo, { 'user.email': 'test@localhost' }),
git.config.set(repo, { 'user.email': 'test@localhost' }),
git.config.set(repo, { 'user.email': 'test@localhost' }),
git.config.set(repo, { 'user.email': 'test@localhost' })
])
})
.then(() => {
t.pass('succeeded this time but expect lock error')
t.end()
})
.catch(error => {
t.true(error instanceof Error, 'is instance of Error')
t.true(error.message.includes('failed to lock file'), 'failed to lock message')
t.equal(error.errno, -14, 'errno -14')
t.end()
})
})

test('config get error', t => {
git.open(resolve(__dirname, './repos/config-get'))
.then(repo => {
git.config.get(repo, {}) // TODO: should this error?
.then(config => {
t.true(config == null, 'got no config')
t.end()
})
.catch(t.end)
})
})

test('config get and set repo configs', t => {
const path = resolve(__dirname, './repos/config-test')

git.init(path, {
'commit': false
})
.then(repo => {
return git.config.set(repo, {
'user': {
'name': 'user1',
'email': 'user1@localhost'
}
})
.then(() => git.init.commit(repo))
// find user.name and user.email (git)
.then(() => exec('git log', { cwd: path }))
.then(stdout => {
const author = 'Author: user1 <user1@localhost>'
t.true(stdout.includes(author), `includes ${author}`)
})
// test user.email config
.then(() => git.config.get(repo, 'user.email'))
.then(email => t.equal(email, 'user1@localhost', 'get user.email from repo config'))
// set user.name config and read it with git
// TODO: .then(() => git.config.set(repo, 'user.name', 'user2'))
.then(() => git.config.set(repo, {
'user.name': 'John Doe'
}))
.then(() => exec('git config --local user.name', { cwd: path }))
.then(stdout => t.equal(stdout, 'John Doe', 'set new username'))
.then(() => exec('git config --local user.email', { cwd: path }))
.then(stdout => t.equal(stdout, 'user1@localhost', 'email is still the same'))
// read updated user.email
.then(() => exec('git config user.email johndoe@example.com', { cwd: path }))
.then(() => git.config.get(repo, 'user.email'))
.then(email => t.equal(email, 'johndoe@example.com', 'got updated email'))
.then(() => git.config.set(repo, {
'user.name': 'Jane Doe',
'core.abbrev': 11,
'core.autocrlf': 'input'
}))
.then(() => git.config.get(repo, ['user.name', 'core.abbrev', 'core.autocrlf']))
.then(([username, abbrev, autocrlf]) => {
t.equal(username, 'Jane Doe', `user.name ${username}`)
t.equal(abbrev, '11', `core.abbrev is ${abbrev}`)
t.equal(typeof abbrev, 'string', `core.abbrev is a string :/`)
t.equal(autocrlf, 'input', 'autocrlf should be set to input')
})
.then(() => exec('git config --local --list', { cwd: path }))
.then(stdout => {
t.pass('stdout from git config --local --list')
t.true(stdout.includes('user.name=Jane Doe'), 'user.name=Jane Doe')
t.true(stdout.includes('user.email=johndoe@example.com'), 'user.email=johndoe@example.com')
t.true(stdout.includes('core.abbrev=11'), 'core.abbrev=11')
t.true(stdout.includes('core.autocrlf=input'), 'core.autocrlf=input')
})

})
.then(t.end)
.catch(t.end)
})

test('config compare defaults to global config', t => {
const path = resolve(__dirname, './repos/config-defaults')
git.open(path)
.then(repo => {
return Promise.all([
git.config.get(repo, ['user.name', 'user.email']),
git.config.get(['user.name', 'user.email']),
exec('git config --global user.name'),
exec('git config --global user.email')
])
.then(([
[reponame, repoemail],
[globalname, globalemail],
gitname, gitemail
]) => {
t.equal(reponame, globalname, 'should be same name')
t.equal(reponame, gitname, 'should be same git name')
t.equal(repoemail, globalemail, 'should be same email')
t.equal(repoemail, gitemail, 'should be same git email')
return [reponame, repoemail]
})
.then(([name, email]) => {
return exec('git log', { cwd: path })
.then(stdout => {
const author = `Author: ${name} <${email}>`
t.true(stdout.includes(author), 'git log includes author')
t.pass(author)
})
})
})
.then(t.end)
.catch(t.end)
})
Loading

0 comments on commit 73057f5

Please sign in to comment.