-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
827 additions
and
934 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
repos | ||
repos/* |
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,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" |
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,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) | ||
}) |
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,5 @@ | ||
#!/bin/sh | ||
mkdir repos/config-git | ||
cd repos/config-git | ||
git init | ||
echo "Hello\n" > file.txt |
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,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) | ||
}) |
Oops, something went wrong.