added some tests
This commit is contained in:
parent
29d176bafa
commit
15c331690b
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -9,4 +9,4 @@ export declare let createRepoFromClone: (fromArg: string, toArg: string) => q.Pr
|
||||
/**
|
||||
* creates a new GitRepo instance after initializing a new Git Repository
|
||||
*/
|
||||
export declare let createRepoFromInit: (destinationDirArg: string) => void;
|
||||
export declare let createRepoFromInit: (destinationDirArg: string) => q.Promise<GitRepo>;
|
||||
|
5
dist/index.js
vendored
5
dist/index.js
vendored
@ -20,8 +20,9 @@ exports.createRepoFromClone = (fromArg, toArg) => {
|
||||
exports.createRepoFromInit = (destinationDirArg) => {
|
||||
let done = q.defer();
|
||||
plugins.smartfile.fs.ensureDir(destinationDirArg);
|
||||
plugins.shelljs.exec(`cd destinationDirArg && git init`);
|
||||
plugins.shelljs.exec(`cd ${destinationDirArg} && git init`);
|
||||
let newRepo = new smartgit_classes_gitrepo_1.GitRepo(destinationDirArg);
|
||||
done.resolve(newRepo);
|
||||
return done.promise;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsdUJBQXNCO0FBQ3RCLDhDQUErQztBQUUvQyx5RUFBb0Q7QUFFaEQscURBQU87QUFHWDs7R0FFRztBQUNRLFFBQUEsbUJBQW1CLEdBQUcsQ0FBQyxPQUFlLEVBQUUsS0FBYTtJQUM1RCxJQUFJLElBQUksR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFXLENBQUE7SUFDN0IsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQyxDQUFBO0lBQ3JDLE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLGFBQWEsT0FBTyxJQUFJLEt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yxDQUFDLEtBQUssQ0FBQyxDQUFBO0lBQ3JDLE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLGFBQWEsT0FBTyxJQUFJLEtBQUssRUFBRSxDQUFDLENBQUE7SUFDckQsSUFBSSxPQUFPLEdBQUcsSUFBSSxrQ0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO0lBQ2hDLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUE7SUFDckIsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7QUFDdkIsQ0FBQyxDQUFBO0FBRUQ7O0dBRUc7QUFDUSxRQUFBLGtCQUFrQixHQUFHLENBQUMsaUJBQXlCO0lBQ3RELElBQUksSUFBSSxHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQVcsQ0FBQTtJQUM3QixPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxTQUFTLENBQUMsaUJBQWlCLENBQUMsQ0FBQTtJQUNqRCxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxNQUFNLGlCQUFpQixjQUFjLENBQUMsQ0FBQTtJQUMzRCxJQUFJLE9BQU8sR0FBRyxJQUFJLGtDQUFPLENBQUMsaUJBQWlCLENBQUMsQ0FBQTtJQUM1QyxJQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFBO0lBQ3JCLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0FBQ3ZCLENBQUMsQ0FBQSJ9
|
2
dist/smartgit.classes.gitrepo.d.ts
vendored
2
dist/smartgit.classes.gitrepo.d.ts
vendored
@ -21,7 +21,7 @@ export declare class GitRepo {
|
||||
/**
|
||||
* list remotes for a Gip
|
||||
*/
|
||||
remoteList(dirPathArg: any): q.Promise<{}>;
|
||||
remoteList(): q.Promise<{}>;
|
||||
/**
|
||||
* remove remote
|
||||
*/
|
||||
|
14
dist/smartgit.classes.gitrepo.js
vendored
14
dist/smartgit.classes.gitrepo.js
vendored
File diff suppressed because one or more lines are too long
1
test/temp3
Submodule
1
test/temp3
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit a261a2ea02b39d8ff8c66b078a894a75a0d4f457
|
47
test/test.js
47
test/test.js
@ -5,7 +5,7 @@ const path = require("path");
|
||||
const should = require("should");
|
||||
const smartgit = require("../dist/index");
|
||||
let paths = {
|
||||
temp: path.resolve('./test/temp/'),
|
||||
temp1: path.resolve('./test/temp/'),
|
||||
temp2: path.resolve('./test/temp2/'),
|
||||
temp3: path.resolve('./test/temp3'),
|
||||
temp4: path.resolve('./test/temp4'),
|
||||
@ -16,13 +16,32 @@ describe('smartgit', function () {
|
||||
let testGitRepoCloned;
|
||||
let testGitRepoInit;
|
||||
describe('instance', function () {
|
||||
it('should create a valid new instance from path', function () {
|
||||
testGitRepo = new smartgit.GitRepo('path.temp');
|
||||
it('should error for invalid path', function (done) {
|
||||
try {
|
||||
testGitRepo = new smartgit.GitRepo(paths.temp1);
|
||||
}
|
||||
catch (err) {
|
||||
should(testGitRepo).not.be.instanceOf(smartgit.GitRepo);
|
||||
done();
|
||||
}
|
||||
});
|
||||
it('should init a new repo', function (done) {
|
||||
this.timeout(40000);
|
||||
smartgit.createRepoFromInit(paths.temp1)
|
||||
.then((gitRepo) => {
|
||||
should(gitRepo).be.instanceOf(smartgit.GitRepo);
|
||||
done();
|
||||
}).catch(err => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
it('should create am instance for an existing repo', function () {
|
||||
testGitRepo = new smartgit.GitRepo(paths.temp1);
|
||||
should(testGitRepo).be.instanceOf(smartgit.GitRepo);
|
||||
});
|
||||
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)
|
||||
smartgit.createRepoFromClone('git@gitlab.com:sandboxzone/sandbox-testrepo.git', paths.temp2)
|
||||
.then((gitRepo) => {
|
||||
should(gitRepo).be.instanceOf(smartgit.GitRepo);
|
||||
done();
|
||||
@ -32,7 +51,7 @@ describe('smartgit', function () {
|
||||
});
|
||||
it('should clone a repository using https', function (done) {
|
||||
this.timeout(40000);
|
||||
smartgit.createRepoFromClone('https://gitlab.com/sandboxzone/sandbox-testrepo.git', paths.temp2)
|
||||
smartgit.createRepoFromClone('https://gitlab.com/sandboxzone/sandbox-testrepo.git', paths.temp3)
|
||||
.then((gitRepo) => {
|
||||
should(gitRepo).be.instanceOf(smartgit.GitRepo);
|
||||
done();
|
||||
@ -43,8 +62,14 @@ describe('smartgit', function () {
|
||||
});
|
||||
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);
|
||||
shelljs.exec(`(cd ${paths.temp1} && cp ../test.js .)`);
|
||||
testGitRepo.addAll(paths.temp1);
|
||||
});
|
||||
});
|
||||
describe('.check()', function (done) {
|
||||
it('should check a git repo', function () {
|
||||
let checkResult = testGitRepo.check();
|
||||
should(checkResult).be.true();
|
||||
});
|
||||
});
|
||||
describe('commit', function () {
|
||||
@ -74,6 +99,12 @@ describe('smartgit', function () {
|
||||
it('should add a remote', function () {
|
||||
testGitRepo.remoteAdd('origin2', 'https://github.com/pushrocks/somerepo');
|
||||
});
|
||||
it('should', function (done) {
|
||||
testGitRepo.remoteList()
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQixJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUE7QUFDaEMsNkJBQTZCO0FBQzdCLGlDQUFnQztBQUVoQywwQ0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QUFDLENBQUMsQ0FBQTtRQUNWLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7SUFDRixRQUFRLENBQUMsUUFBUSxFQUFFO1FBQ2YsRUFBRSxDQUFDLHFCQUFxQixFQUFFO1lBQ3RCLFdBQVcsQ0FBQyxTQUFTLENBQUMsU0FBUyxFQUFFLHVDQUF1QyxDQUFDLENBQUE7UUFDN0UsQ0FBQyxDQUFDLENBQUE7UUFDRixFQUFFLENBQUMsUUFBUSxFQUFFLFVBQVMsSUFBSTtZQUN0QixXQUFXLENBQUMsVUFBVSxFQUFFO2lCQUNuQixJQUFJLENBQUM7Z0JBQ0YsSUFBSSxFQUFFLENBQUE7WUFDVixDQUFDLENBQUMsQ0FBQTtRQUNWLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9
|
46
test/test.ts
46
test/test.ts
@ -6,25 +6,45 @@ import * as should from 'should'
|
||||
|
||||
import smartgit = require('../dist/index')
|
||||
let paths = {
|
||||
temp: path.resolve('./test/temp/'),
|
||||
temp1: path.resolve('./test/temp/'),
|
||||
temp2: path.resolve('./test/temp2/'),
|
||||
temp3: path.resolve('./test/temp3'),
|
||||
temp4: path.resolve('./test/temp4'),
|
||||
noGit: path.resolve('./test/')
|
||||
}
|
||||
|
||||
|
||||
|
||||
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')
|
||||
it('should error for invalid path', function (done) {
|
||||
try {
|
||||
testGitRepo = new smartgit.GitRepo(paths.temp1)
|
||||
} catch (err) {
|
||||
should(testGitRepo).not.be.instanceOf(smartgit.GitRepo)
|
||||
done()
|
||||
}
|
||||
})
|
||||
it('should init a new repo', function (done) {
|
||||
this.timeout(40000)
|
||||
smartgit.createRepoFromInit(paths.temp1)
|
||||
.then((gitRepo) => {
|
||||
should(gitRepo).be.instanceOf(smartgit.GitRepo)
|
||||
done()
|
||||
}).catch(err => {
|
||||
throw err
|
||||
})
|
||||
})
|
||||
it('should create am instance for an existing repo', function () {
|
||||
testGitRepo = new smartgit.GitRepo(paths.temp1)
|
||||
should(testGitRepo).be.instanceOf(smartgit.GitRepo)
|
||||
})
|
||||
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)
|
||||
smartgit.createRepoFromClone('git@gitlab.com:sandboxzone/sandbox-testrepo.git', paths.temp2)
|
||||
.then((gitRepo) => {
|
||||
should(gitRepo).be.instanceOf(smartgit.GitRepo)
|
||||
done()
|
||||
@ -34,7 +54,7 @@ describe('smartgit', function () {
|
||||
})
|
||||
it('should clone a repository using https', function (done) {
|
||||
this.timeout(40000)
|
||||
smartgit.createRepoFromClone('https://gitlab.com/sandboxzone/sandbox-testrepo.git', paths.temp2)
|
||||
smartgit.createRepoFromClone('https://gitlab.com/sandboxzone/sandbox-testrepo.git', paths.temp3)
|
||||
.then((gitRepo) => {
|
||||
should(gitRepo).be.instanceOf(smartgit.GitRepo)
|
||||
done()
|
||||
@ -45,8 +65,14 @@ describe('smartgit', function () {
|
||||
})
|
||||
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)
|
||||
shelljs.exec(`(cd ${paths.temp1} && cp ../test.js .)`)
|
||||
testGitRepo.addAll(paths.temp1)
|
||||
})
|
||||
})
|
||||
describe('.check()', function(done) {
|
||||
it('should check a git repo', function() {
|
||||
let checkResult = testGitRepo.check()
|
||||
should(checkResult).be.true()
|
||||
})
|
||||
})
|
||||
describe('commit', function () {
|
||||
@ -76,5 +102,11 @@ describe('smartgit', function () {
|
||||
it('should add a remote', function () {
|
||||
testGitRepo.remoteAdd('origin2', 'https://github.com/pushrocks/somerepo')
|
||||
})
|
||||
it('should', function(done) {
|
||||
testGitRepo.remoteList()
|
||||
.then(() => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -24,7 +24,8 @@ export let createRepoFromClone = (fromArg: string, toArg: string) => {
|
||||
export let createRepoFromInit = (destinationDirArg: string) => {
|
||||
let done = q.defer<GitRepo>()
|
||||
plugins.smartfile.fs.ensureDir(destinationDirArg)
|
||||
plugins.shelljs.exec(`cd destinationDirArg && git init`)
|
||||
plugins.shelljs.exec(`cd ${destinationDirArg} && git init`)
|
||||
let newRepo = new GitRepo(destinationDirArg)
|
||||
done.resolve(newRepo)
|
||||
return done.promise
|
||||
}
|
||||
|
@ -8,17 +8,16 @@ export class GitRepo {
|
||||
repoBase: string
|
||||
constructor(repoBaseArg: string) {
|
||||
this.repoBase = repoBaseArg
|
||||
if (!this.check()) {
|
||||
throw new Error('no valid git repo')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the Repo is valid
|
||||
*/
|
||||
check(): boolean {
|
||||
try {
|
||||
return plugins.smartfile.fs.isDirectory(plugins.path.join(this.repoBase, '.git'))
|
||||
} catch (err) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,10 +57,10 @@ export class GitRepo {
|
||||
/**
|
||||
* list remotes for a Gip
|
||||
*/
|
||||
remoteList(dirPathArg) {
|
||||
remoteList() {
|
||||
let done = q.defer()
|
||||
let remotes = {}
|
||||
plugins.shelljs.exec(`cd ${dirPathArg} && git remote -v`)
|
||||
plugins.shelljs.exec(`cd ${this.repoBase} && git remote -v`)
|
||||
done.resolve(remotes)
|
||||
return done.promise
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user