-
Notifications
You must be signed in to change notification settings - Fork 0
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
blond
committed
Feb 25, 2016
1 parent
4b99e7b
commit 1050506
Showing
20 changed files
with
593 additions
and
9 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,3 @@ | ||
{ | ||
"presets": ["nodejs-lts"] | ||
} |
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,4 @@ | ||
node_modules | ||
lib | ||
coverage | ||
.nyc_output |
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,5 +1,34 @@ | ||
sudo: false | ||
|
||
language: node_js | ||
node_js: | ||
- '5' | ||
- '4' | ||
|
||
matrix: | ||
include: | ||
- node_js: "4" | ||
env: COVERALLS=1 | ||
- node_js: "5" | ||
|
||
# This is a random private key used purely for testing. | ||
before_script: | ||
- echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config | ||
- echo -e "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDkTcgXnHuqR0gbwegnr9Zxz4hTkjjV/SpgJNPJz7mo/HKNbx0rqjj1P0yGR053R9GSFFim2ut4NK9DPPUkQdyucw+DoLkYRHJmlJ4BNa9NTCD0sl+eSXO2969kZojCYSOgbmkCJx8mdgTwhzdgE/jhBrsY0hPE6pRTlU+H68/zeNdJUAIJf0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F9QE1+2M03r\nkS6138gU/CSCLf8pCYa6pA/GmsaXxloeJGLvT4fzOZRsVav80/92XHRhAoGBAOu2\nmKh4Gr1EjgN9QNbk9cQTSFDtlBEqO/0pTepvL73UvNp/BAn4iYZFU4WnklFVBSWc\nL84Sc732xU12TAbTTUsa6E7W29pS8u7zVTxlIdQIIU5pzDyU1pNNk2kpxzte5p3Y\nPDtniPFsoYLWoH0LpsKL93t2pLAj+IOkE6f3XBq5AoGAIKaYo5N1FxQr952frx/x\nQUpK0N/R5Ng8v18SiLG26rhmM5iVSrQXC7TrHI7wfR8a9tC6qP/NqnM9NuwC/bQ0\nEEo7/GhaWxKNRwZRkmWiSFLNGk9t1hbtGU+N1lUdFtmloPIQdRNiw0kN3JTj474Q\nYI7O1EItFORnK6yxZfR6HEECgYEA1CT7MGUoa8APsMRCXyaiq15Pb8bjxK8mXquW\nHLEFXuzhLCW1FORDoj0y9s/iuKC0iS0ROX8R/J7k5NrbgikbH8WP36UxKkYNr1IC\nHOFImPTYRSKjVsL+fIUNb1DSp3S6SsYbL7v3XJJQqtlQiDq8U8x1aQFXJ9C4EoLR\nzhKrKsECgYBtU/TSF/TATZY5XtrN9O+HX1Fbz70Ci8XgvioheVI2fezOcXPRzDcC\nOYPaCMNKA5E8gHdg4s0TN7uDvKTJ+KhSg2V7gZ39A28dHrJaRX7Nz4k6t2uEBjX9\na1JidpAIbJ+3w7+hj6L299tVZvS+Y/6Dz/uuEQGXfJg/l/5CCvQPsA==\n-----END RSA PRIVATE KEY-----" > ~/.ssh/id_rsa | ||
- chmod 600 ~/.ssh/id_rsa* | ||
- eval `ssh-agent -s` | ||
- ssh-add ~/.ssh/id_rsa | ||
- git config --global user.name travis | ||
- git config --global user.email travis@locahost | ||
|
||
after_success: | ||
- if [ "x$COVERALLS" = "x1" ]; then npm run coveralls; fi | ||
|
||
# It is necessary for nodegit | ||
# https://github.com/nodegit/nodegit#getting-started | ||
addons: | ||
apt: | ||
sources: | ||
- ubuntu-toolchain-r-test | ||
packages: | ||
- libstdc++-4.9-dev | ||
- gcc-4.9 | ||
- g++-4.9 |
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,13 +1,21 @@ | ||
environment: | ||
nodejs_version: "4" | ||
|
||
clone_folder: c:\projects\nodegit-clone | ||
|
||
# fix lineendings in Windows | ||
init: | ||
- git config --global core.autocrlf input | ||
- git config --global user.name appveyor | ||
- git config --global user.email appveyor@locahost | ||
|
||
install: | ||
- ps: Install-Product node $env:nodejs_version | ||
- node --version | ||
- npm --version | ||
- npm install | ||
|
||
test_script: | ||
- npm run test | ||
- npm run unit-test | ||
|
||
build: "off" |
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,54 @@ | ||
import os from 'os'; | ||
|
||
import git from 'nodegit'; | ||
import isSSH from 'is-ssh'; | ||
|
||
import init from './init'; | ||
|
||
/** | ||
* Clones repository to `localPath`. | ||
* | ||
* @param {Object} opts Options or url of the repository. | ||
* @param {String} opts.url The URL to the repository. | ||
* @param {String} [opts.localPath] The Local path to store repository. | ||
* @param {String} [opts.ghToken] The GitHub personal OAuth token. | ||
* @param {Object} [opts.ssh] The object with paths to ssh keys and passphrase. | ||
* @param {String} [opts.ssh.publicKey] The path to the public key of the credential. | ||
* @param {String} [opts.ssh.privateKey] The path to the private key of the credential. | ||
* @param {String} [opts.ssh.passphrase] The passphrase of the credential. | ||
* | ||
* @returns {Promise<Git.Repository>} A promise `Git.Repository` instance. | ||
* @see [Git.Repository]{@link http://www.nodegit.org/api/repository/} | ||
*/ | ||
export default function clone(opts) { | ||
const { url, localPath, ghToken, ssh } = init(opts); | ||
|
||
const cloneOpts = { fetchOpts: {} }; | ||
const callbacks = cloneOpts.fetchOpts.callbacks = {}; | ||
|
||
if (os.type() === 'Darwin'/* OS X */) { | ||
// This is a required callback for OS X machines. There is a known issue | ||
// with libgit2 being able to verify certificates from GitHub. | ||
callbacks.certificateCheck = () => 1; | ||
} | ||
|
||
if (ghToken) { | ||
callbacks.certificateCheck = () => 1; | ||
callbacks.credentials = () => { | ||
// In order to authorize the clone operation, we'll need to respond to a low-level callback | ||
// that expects credentials to be passed. | ||
// This function will respond back with the OAuth token. | ||
return git.Cred.userpassPlaintextNew(ghToken, "x-oauth-basic"); | ||
}; | ||
} else if (ssh.publicKey || isSSH(url)) { | ||
callbacks.credentials = (url, username) => { | ||
// Forward user name to validate authentication. | ||
return git.Cred.sshKeyFromAgent(username, ssh.publicKey, ssh.privateKey, ssh.passphrase); | ||
}; | ||
} | ||
|
||
// Convert NodeGit promise to ES Promise | ||
return new Promise((resolve, reject) => { | ||
git.Clone(url, localPath, cloneOpts).then(resolve, reject); | ||
}); | ||
} |
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,20 @@ | ||
import path from 'path'; | ||
import thr from 'throw'; | ||
|
||
import repoName from './repo-name'; | ||
|
||
/** | ||
* Initializes options. | ||
* | ||
* @param {Object} opts | ||
* @returns {String} | ||
*/ | ||
export default function init(opts={}) { | ||
const { | ||
url = (typeof opts === 'string') ? opts : thr('You should specify url to repository.'), | ||
localPath = repoName(url), | ||
ghToken, ssh={} | ||
} = opts; | ||
|
||
return { url, localPath: path.resolve(localPath), ghToken, ssh }; | ||
} |
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,11 @@ | ||
import path from 'path'; | ||
|
||
/** | ||
* Returns repository name. | ||
* | ||
* @param {String} url — url of the repository. | ||
* @returns {String} | ||
*/ | ||
export default function getRepoName(url) { | ||
return path.basename(url, '.git'); | ||
} |
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,45 @@ | ||
import path from 'path'; | ||
|
||
import test from 'ava'; | ||
import fs from 'fs-extra'; | ||
import promisify from 'es6-promisify'; | ||
|
||
import clone from '../src/clone'; | ||
import tmpdirs from './utils/tmpdirs'; | ||
|
||
const outputFile = promisify(fs.outputFile); | ||
const tmps = tmpdirs(); | ||
const tmpdir = tmps.tmpdir.bind(tmpdirs); | ||
|
||
test.after('clear', () => tmps.clear()); | ||
|
||
test('should throw error if local store of repository already exists', t => { | ||
const url = 'git://github.com/nodegit/fake.git'; | ||
const workdir = tmpdir(); | ||
|
||
return t.throws( | ||
occupy(workdir).then(() => clone({ url: url, localPath: workdir })) | ||
); | ||
}); | ||
|
||
test('should throw error if repository does not exist', t => { | ||
return t.throws( | ||
clone({ url: 'git://github.com/nodegit/fake.git', localPath: tmpdir() }) | ||
); | ||
}); | ||
|
||
test('should throw error if page does not exist', t => { | ||
return t.throws( | ||
clone({ url: 'http://github.com/nodegit/fake', localPath: tmpdir() }) | ||
); | ||
}); | ||
|
||
/** | ||
* @param {String} dir — path to dir. | ||
* @returns {Promise} | ||
*/ | ||
function occupy(dir) { | ||
const filename = path.join(dir, 'some-file.txt'); | ||
|
||
return outputFile(filename, 'text'); | ||
} |
Oops, something went wrong.