2016-11-22 20:49:40 +00:00
|
|
|
import 'typings-test'
|
|
|
|
import beautylog = require('beautylog')
|
|
|
|
let shelljs = require('shelljs')
|
|
|
|
import path = require('path')
|
|
|
|
import * as should from 'should'
|
2016-06-12 14:46:59 +00:00
|
|
|
|
2016-11-22 20:49:40 +00:00
|
|
|
import smartgit = require('../dist/index')
|
2016-07-03 22:00:04 +00:00
|
|
|
let paths = {
|
2016-11-22 20:49:40 +00:00
|
|
|
temp: path.resolve('./test/temp/'),
|
|
|
|
temp2: path.resolve('./test/temp2/'),
|
|
|
|
temp3: path.resolve('./test/temp3'),
|
|
|
|
temp4: path.resolve('./test/temp4'),
|
|
|
|
noGit: path.resolve('./test/')
|
2016-07-03 22:00:04 +00:00
|
|
|
}
|
2016-03-30 23:59:45 +00:00
|
|
|
|
2016-11-22 20:49:40 +00:00
|
|
|
describe('smartgit', function () {
|
|
|
|
let testGitRepo: smartgit.GitRepo
|
|
|
|
let testGitRepoCloned: smartgit.GitRepo
|
|
|
|
let testGitRepoInit: smartgit.GitRepo
|
|
|
|
describe('instance', function () {
|
|
|
|
it('should create a valid new instance from path', function () {
|
|
|
|
testGitRepo = new smartgit.GitRepo('path.temp')
|
|
|
|
should(testGitRepo).be.instanceOf(smartgit.GitRepo)
|
2016-07-03 22:00:04 +00:00
|
|
|
})
|
2016-11-22 20:49:40 +00:00
|
|
|
it('should clone a repository using ssh and sshkey', function (done) {
|
|
|
|
this.timeout(40000)
|
|
|
|
smartgit.createRepoFromClone('git@gitlab.com:sandboxzone/sandbox-testrepo.git', paths.temp)
|
|
|
|
.then((gitRepo) => {
|
|
|
|
should(gitRepo).be.instanceOf(smartgit.GitRepo)
|
|
|
|
done()
|
|
|
|
}).catch(err => {
|
|
|
|
throw err
|
|
|
|
})
|
|
|
|
})
|
|
|
|
it('should clone a repository using https', function (done) {
|
|
|
|
this.timeout(40000)
|
|
|
|
smartgit.createRepoFromClone('https://gitlab.com/sandboxzone/sandbox-testrepo.git', paths.temp2)
|
|
|
|
.then((gitRepo) => {
|
|
|
|
should(gitRepo).be.instanceOf(smartgit.GitRepo)
|
|
|
|
done()
|
|
|
|
}).catch(err => {
|
|
|
|
throw err
|
|
|
|
})
|
2016-07-03 22:00:04 +00:00
|
|
|
})
|
2016-11-22 20:49:40 +00:00
|
|
|
})
|
|
|
|
describe('.add', function () {
|
|
|
|
it('should add a file to an existing repository', function () {
|
|
|
|
shelljs.exec(`(cd ${paths.temp} && cp ../test.js .)`)
|
|
|
|
testGitRepo.addAll(paths.temp)
|
2016-07-03 22:00:04 +00:00
|
|
|
})
|
2016-11-22 20:49:40 +00:00
|
|
|
})
|
|
|
|
describe('commit', function () {
|
|
|
|
it('should commit a new file to an existing repository', function () {
|
|
|
|
testGitRepo.commit('added a new file')
|
2016-07-03 22:00:04 +00:00
|
|
|
})
|
2016-11-22 20:49:40 +00:00
|
|
|
})
|
|
|
|
describe('pull', function () {
|
|
|
|
this.timeout(40000)
|
|
|
|
it('should pull from origin', function (done) {
|
|
|
|
testGitRepo.pull()
|
|
|
|
.then(() => {
|
|
|
|
done()
|
|
|
|
})
|
2016-07-03 22:00:04 +00:00
|
|
|
})
|
2016-11-22 20:49:40 +00:00
|
|
|
})
|
|
|
|
describe('push', function () {
|
|
|
|
this.timeout(40000)
|
|
|
|
it('should push to origin', function (done) {
|
|
|
|
testGitRepo.push('origin', 'master')
|
|
|
|
.then(() => {
|
|
|
|
done()
|
|
|
|
})
|
2016-07-03 22:00:04 +00:00
|
|
|
})
|
2016-11-22 20:49:40 +00:00
|
|
|
})
|
|
|
|
describe('remote', function () {
|
|
|
|
it('should add a remote', function () {
|
|
|
|
testGitRepo.remoteAdd('origin2', 'https://github.com/pushrocks/somerepo')
|
2016-07-05 01:47:38 +00:00
|
|
|
})
|
2016-11-22 20:49:40 +00:00
|
|
|
})
|
|
|
|
})
|