Compare commits

...

11 Commits

Author SHA1 Message Date
ff0318534f 1.0.6 2019-06-18 15:17:50 +02:00
e103074684 fix(core): update 2019-06-18 15:17:50 +02:00
f72beabd90 remove some white space 2016-12-31 23:20:38 +01:00
958a625633 1.0.5 2016-12-31 23:17:07 +01:00
871fd55c5c fix .addAll 2016-12-31 23:17:03 +01:00
07fd9b9fa7 1.0.4 2016-11-26 23:28:41 +01:00
62d6a8d685 add npmextra.json 2016-11-26 23:28:37 +01:00
047cf02e6a 1.0.3 2016-11-26 23:24:52 +01:00
69127cacdd remove postinstall 2016-11-26 23:24:48 +01:00
7529098a50 1.0.2 2016-11-22 22:22:32 +01:00
15c331690b added some tests 2016-11-22 22:22:24 +01:00
21 changed files with 2805 additions and 677 deletions

25
.gitignore vendored
View File

@ -1,13 +1,22 @@
node_modules/
test/temp/
test/temp2/
.nogit/
# artifacts
coverage/
public/
pages/
#npm debug
npm-debug.log
# installs
node_modules/
ts/*.js
ts/*.js.map
ts/typings/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,49 +1,117 @@
image: hosttoday/ht-docker-node:npmts
# gitzone ci_default
image: hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages:
- security
- test
- release
- trigger
- metadata
before_script:
- npmci prepare ssh
testLEGACY:
stage: test
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci test legacy
- npmci git mirror
tags:
- docker
allow_failure: true
- notpriv
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
# ====================
# test stage
# ====================
testLTS:
stage: test
script:
- npmci test lts
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
stage: test
script:
- npmci test stable
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
release:
stage: release
script:
- npmci publish
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
trigger:
stage: trigger
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

View File

@ -1,30 +1,28 @@
# smartgit
smart git wrapper for node.
# @pushrocks/smartgit
smart wrapper for nodegit
smartgit expects git to be installed on target machine.
## Availabililty
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartgit)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/smartgit)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartgit)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartgit/)
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartgit)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartgit)
* [github.com (source mirror)](https://github.com/pushrocks/smartgit)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartgit/)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartgit/badges/master/build.svg)](https://gitlab.com/pushrocks/smartgit/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartgit/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartgit/commits/master)
[![Dependency Status](https://david-dm.org/pushrocks/smartgit.svg)](https://david-dm.org/pushrocks/smartgit)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartgit/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartgit/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartgit/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartgit)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartgit.svg)](https://www.npmjs.com/package/@pushrocks/smartgit)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartgit/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartgit)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
## Usage
We recommend the use of TypeScript for best in class intellisense
```javascript
// import smartgit:
import { GitRepo } from 'smartgit'
import { GitRepo } from 'smartgit';
// Initialize smartgit:
// -- note: there are 3 ways to initialize smartgit
@ -33,36 +31,46 @@ import { GitRepo } from 'smartgit'
// -- -- 3. with a new Git repo
// -- 1. existing Git Repo:
let myExistingGitRepo = new GitRepo('/path/to/existing/git/repo/')
let myExistingGitRepo = new GitRepo('/path/to/existing/git/repo/');
// -- 2. cloned Git Repo:
let myClonedGitRepo: GitRepo
smartgit.createRepoFromClone('git@github.com:username/reponame.git')
.then(gitRepo => { // non blocking
myClonedGitRepo = gitRepo
})
let myClonedGitRepo: GitRepo;
smartgit.createRepoFromClone('git@github.com:username/reponame.git').then(gitRepo => {
// non blocking
myClonedGitRepo = gitRepo;
});
// -- 3. new Git Repo
let myNewGitRepo: GitRepo
smartgit.createRepoFromInit('/path/to/new/folder') // smartgit will create any new folder, be careful
.then(gitRepo => { // non blocking
myNewGitRepo = gitRepo
})
let myNewGitRepo: GitRepo;
smartgit
.createRepoFromInit('/path/to/new/folder') // smartgit will create any new folder, be careful
.then(gitRepo => {
// non blocking
myNewGitRepo = gitRepo;
});
// Using smartgit instance
// -- most used actions
// -- all actions return promises, so make sure to use promise chaining for any dependent tasks
myExistingGitRepo.addAll() // returns promise, stages all changed files
myExistingGitRepo.add(['relative/path/to/file.txt','another/file2.txt']) // returns promise, stages specific files
myExistingGitRepo.commit('my commit message') // returns promise, commits staged files
myExistingGitRepo.status() // returns promise
.then(status => { // Use TypeScript for status type information
})
myExistingGitRepo.check() // returns promise, checks repo health
myExistingGitRepo.remoteAdd('git@github.com:username/reponame.git')
myExistingGitRepo.addAll(); // returns promise, stages all changed files
myExistingGitRepo.add(['relative/path/to/file.txt', 'another/file2.txt']); // returns promise, stages specific files
myExistingGitRepo.commit('my commit message'); // returns promise, commits staged files
myExistingGitRepo
.status() // returns promise
.then(status => {
// Use TypeScript for status type information
});
myExistingGitRepo.check(); // returns promise, checks repo health
myExistingGitRepo.remoteAdd('git@github.com:username/reponame.git');
```
Tip: use [smartssh](https://npmjs.com/smartssh) to setup your SSH environment
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)

12
dist/index.d.ts vendored
View File

@ -1,12 +0,0 @@
/// <reference types="q" />
import * as q from 'q';
import { GitRepo } from './smartgit.classes.gitrepo';
export { GitRepo };
/**
* creates a new GitRepo Instance after cloning a project
*/
export declare let createRepoFromClone: (fromArg: string, toArg: string) => q.Promise<GitRepo>;
/**
* creates a new GitRepo instance after initializing a new Git Repository
*/
export declare let createRepoFromInit: (destinationDirArg: string) => void;

27
dist/index.js vendored
View File

@ -1,27 +0,0 @@
"use strict";
const q = require("q");
const plugins = require("./smartgit.plugins");
const smartgit_classes_gitrepo_1 = require("./smartgit.classes.gitrepo");
exports.GitRepo = smartgit_classes_gitrepo_1.GitRepo;
/**
* creates a new GitRepo Instance after cloning a project
*/
exports.createRepoFromClone = (fromArg, toArg) => {
let done = q.defer();
plugins.smartfile.fs.ensureDir(toArg);
plugins.shelljs.exec(`git clone ${fromArg} ${toArg}`);
let newRepo = new smartgit_classes_gitrepo_1.GitRepo(toArg);
done.resolve(newRepo);
return done.promise;
};
/**
* creates a new GitRepo instance after initializing a new Git Repository
*/
exports.createRepoFromInit = (destinationDirArg) => {
let done = q.defer();
plugins.smartfile.fs.ensureDir(destinationDirArg);
plugins.shelljs.exec(`cd destinationDirArg && git init`);
let newRepo = new smartgit_classes_gitrepo_1.GitRepo(destinationDirArg);
done.resolve(newRepo);
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsdUJBQXNCO0FBQ3RCLDhDQUErQztBQUUvQyx5RUFBb0Q7QUFFaEQscURBQU87QUFHWDs7R0FFRztBQUNRLFFBQUEsbUJBQW1CLEdBQUcsQ0FBQyxPQUFlLEVBQUUsS0FBYTtJQUM1RCxJQUFJLElBQUksR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFXLENBQUE7SUFDN0IsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQyxDQUFBO0lBQ3JDLE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLGFBQWEsT0FBTyxJQUFJLEtBQUssRUFBRSxDQUFDLENBQUE7SUFDckQsSUFBSSxPQUFPLEdBQUcsSUFBSSxrQ0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO0lBQ2hDLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUE7SUFDckIsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7QUFDdkIsQ0FBQyxDQUFBO0FBRUQ7O0dBRUc7QUFDUSxRQUFBLGtCQUFrQixHQUFHLENBQUMsaUJBQXlCO0lBQ3RELElBQUksSUFBSSxHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQVcsQ0FBQTtJQUM3QixPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxTQUFTLENBQUMsaUJBQWlCLENBQUMsQ0FBQTtJQUNqRCxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxrQ0FBa0MsQ0FBQyxDQUFBO0lBQ3hELElBQUksT0FBTyxHQUFHLElBQUksa0NBQU8sQ0FBQyxpQkFBaUIsQ0FBQyxDQUFBO0lBQzVDLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUE7QUFDekIsQ0FBQyxDQUFBIn0=

View File

@ -1,57 +0,0 @@
/// <reference types="q" />
import * as q from 'q';
/**
* class GitRepo allows access to git directories from node
*/
export declare class GitRepo {
repoBase: string;
constructor(repoBaseArg: string);
/**
* checks if the Repo is valid
*/
check(): boolean;
/**
* stage all files in working directory
*/
addAll(dirPathArg: string): q.Promise<{}>;
/**
* add a remote to the GitRepo
*/
remoteAdd(remoteNameArg: string, remoteLinkArg: string): q.Promise<{}>;
/**
* list remotes for a Gip
*/
remoteList(dirPathArg: any): q.Promise<{}>;
/**
* remove remote
*/
remoteRemove(dirPathArg: string): q.Promise<{}>;
/**
* commit all files that are currently staged
*/
commit(commitMessage: string): q.Promise<{}>;
/**
* pull latest changes from remote
*/
pull(sourceArg?: string, branchArg?: string): q.Promise<{}>;
/**
* push new commits to remote
*/
push(remoteNameArg?: string, remoteBranchArg?: string): q.Promise<{}>;
/**
* sync
*/
sync(): void;
/**
* get the current status
*/
status(): q.Promise<{}>;
}
/**
* creates a new GitRepo Instance after cloning a project
*/
export declare let createRepoFromClone: (fromArg: string, toArg: string) => q.Promise<GitRepo>;
/**
* creates a new GitRepo instance after initializing a new Git Repository
*/
export declare let createRepoFromInit: (destinationDirArg: string) => void;

File diff suppressed because one or more lines are too long

View File

@ -1,7 +0,0 @@
import 'typings-global';
export import path = require('path');
export import beautylog = require('beautylog');
export import shelljs = require('shelljs');
export import smartfile = require('smartfile');
export import smartpath = require('smartpath');
export import smartstring = require('smartstring');

View File

@ -1,9 +0,0 @@
"use strict";
require("typings-global");
exports.path = require("path");
exports.beautylog = require("beautylog");
exports.shelljs = require("shelljs");
exports.smartfile = require("smartfile");
exports.smartpath = require("smartpath");
exports.smartstring = require("smartstring");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRnaXQucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Z2l0LnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2QiwrQkFBb0M7QUFDcEMseUNBQThDO0FBQzlDLHFDQUEwQztBQUMxQyx5Q0FBOEM7QUFDOUMseUNBQThDO0FBQzlDLDZDQUFrRCJ9

22
npmextra.json Normal file
View File

@ -0,0 +1,22 @@
{
"npmts": {
"mode": "default",
"codecov": true,
"coverageTreshold": 71
},
"npmci": {
"globalNpmTools": [
"npmts"
]
},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartgit",
"shortDescription": "smart wrapper for nodegit",
"npmPackagename": "@pushrocks/smartgit",
"license": "MIT"
}
}
}

View File

@ -1,5 +0,0 @@
{
"mode":"default",
"codecov":true,
"coverageTreshold":71
}

2535
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,12 @@
{
"name": "smartgit",
"version": "1.0.1",
"description": "smart git wrapper for node",
"name": "@pushrocks/smartgit",
"version": "1.0.6",
"description": "smart wrapper for nodegit",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"cleanTest": "rm -rf test/temp*",
"test": "(npm run cleanTest && npmts)",
"install": "node dist/postinstall.js"
"test": "(tstest test/)",
"build": "(tsbuild)"
},
"repository": {
"type": "git",
@ -25,21 +24,31 @@
},
"homepage": "https://gitlab.com/pushrocks/smartgit",
"dependencies": {
"@types/minimatch": "*",
"@types/shelljs": "^0.3.32",
"beautylog": "^6.0.0",
"q": "^1.4.1",
"shelljs": "^0.7.5",
"simple-git": "^1.62.0",
"smartfile": "^4.1.0",
"smartpath": "^3.2.5",
"smartstring": "^2.0.22",
"typings-global": "^1.0.14"
"@pushrocks/smartfile": "^7.0.2",
"@pushrocks/smartpath": "^4.0.1",
"@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartshell": "^2.0.23",
"@pushrocks/smartstring": "^3.0.10",
"@types/minimatch": "^3.0.3",
"@types/nodegit": "^0.24.8",
"nodegit": "^0.24.3"
},
"devDependencies": {
"@types/should": "^8.1.30",
"npmts-g": "^5.2.8",
"should": "^11.1.1",
"typings-test": "^1.0.3"
}
"@gitzone/tsbuild": "^2.1.11",
"@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.9",
"tslint": "^5.17.0",
"tslint-config-prettier": "^1.18.0"
},
"private": false,
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}

1
test/test.d.ts vendored
View File

@ -1 +0,0 @@
import 'typings-test';

View File

@ -1,79 +0,0 @@
"use strict";
require("typings-test");
let shelljs = require('shelljs');
const path = require("path");
const should = require("should");
const smartgit = require("../dist/index");
let paths = {
temp: 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;
let testGitRepoCloned;
let testGitRepoInit;
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);
});
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;
});
});
});
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);
});
});
describe('commit', function () {
it('should commit a new file to an existing repository', function () {
testGitRepo.commit('added a new file');
});
});
describe('pull', function () {
this.timeout(40000);
it('should pull from origin', function (done) {
testGitRepo.pull()
.then(() => {
done();
});
});
});
describe('push', function () {
this.timeout(40000);
it('should push to origin', function (done) {
testGitRepo.push('origin', 'master')
.then(() => {
done();
});
});
});
describe('remote', function () {
it('should add a remote', function () {
testGitRepo.remoteAdd('origin2', 'https://github.com/pushrocks/somerepo');
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQixJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUE7QUFDaEMsNkJB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"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,IAAI,QAAQ,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC3C,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACrC,IAAI,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC3B,IAAI,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE/B,QAAQ,CAAC,UAAU,EAAC;IAChB,QAAQ,CAAC,QAAQ,EAAC;QACd,EAAE,CAAC,2BAA2B,EAAC,UAAS,IAAI;YACxC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACpB,QAAQ,CAAC,KAAK,CAAC;gBACX,IAAI,EAAC,uCAAuC;gBAC5C,EAAE,EAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC;aAClC,CAAC,CAAC,IAAI,CAAC;gBACJ,IAAI,EAAE,CAAC;YACX,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,QAAQ,EAAC;IAElB,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,QAAQ,EAAC;IAElB,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,MAAM,EAAC;IAEhB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

View File

@ -1,80 +1,4 @@
import 'typings-test'
import beautylog = require('beautylog')
let shelljs = require('shelljs')
import path = require('path')
import * as should from 'should'
import { tap, expect } from '@pushrocks/tapbundle';
import * as smartgit from '../ts/index';
import smartgit = require('../dist/index')
let paths = {
temp: 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')
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)
.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
})
})
})
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)
})
})
describe('commit', function () {
it('should commit a new file to an existing repository', function () {
testGitRepo.commit('added a new file')
})
})
describe('pull', function () {
this.timeout(40000)
it('should pull from origin', function (done) {
testGitRepo.pull()
.then(() => {
done()
})
})
})
describe('push', function () {
this.timeout(40000)
it('should push to origin', function (done) {
testGitRepo.push('origin', 'master')
.then(() => {
done()
})
})
})
describe('remote', function () {
it('should add a remote', function () {
testGitRepo.remoteAdd('origin2', 'https://github.com/pushrocks/somerepo')
})
})
})
tap.start();

View File

@ -1,30 +1,28 @@
import * as q from 'q'
import plugins = require("./smartgit.plugins");
import plugins = require('./smartgit.plugins');
import { GitRepo } from './smartgit.classes.gitrepo'
export {
GitRepo
}
import { GitRepo } from './smartgit.classes.gitrepo';
export { GitRepo };
/**
* creates a new GitRepo Instance after cloning a project
*/
export let createRepoFromClone = (fromArg: string, toArg: string) => {
let done = q.defer<GitRepo>()
plugins.smartfile.fs.ensureDir(toArg)
plugins.shelljs.exec(`git clone ${fromArg} ${toArg}`)
let newRepo = new GitRepo(toArg)
done.resolve(newRepo)
return done.promise
}
export const createRepoFromClone = async (fromArg: string, toArg: string): Promise<GitRepo> => {
let done = q.defer<GitRepo>();
plugins.smartfile.fs.ensureDir(toArg);
plugins.shelljs.exec(`git clone ${fromArg} ${toArg}`);
let newRepo = new GitRepo(toArg);
done.resolve(newRepo);
return done.promise;
};
/**
* creates a new GitRepo instance after initializing a new Git Repository
*/
export let createRepoFromInit = (destinationDirArg: string) => {
let done = q.defer<GitRepo>()
plugins.smartfile.fs.ensureDir(destinationDirArg)
plugins.shelljs.exec(`cd destinationDirArg && git init`)
let newRepo = new GitRepo(destinationDirArg)
done.resolve(newRepo)
}
export const createRepoFromInit = async (destinationDirArg: string): Promise<GitRepo> => {
const done = q.defer<GitRepo>();
plugins.smartfile.fs.ensureDir(destinationDirArg);
plugins.shelljs.exec(`cd ${destinationDirArg} && git init`);
let newRepo = new GitRepo(destinationDirArg);
done.resolve(newRepo);
return done.promise;
};

View File

@ -1,151 +1,24 @@
import * as q from 'q'
import * as plugins from './smartgit.plugins'
import * as plugins from './smartgit.plugins';
/**
* class GitRepo allows access to git directories from node
*/
export class GitRepo {
repoBase: string
constructor(repoBaseArg: string) {
this.repoBase = repoBaseArg
}
/**
* checks if the Repo is valid
*/
check(): boolean {
try {
return plugins.smartfile.fs.isDirectory(plugins.path.join(this.repoBase, '.git'))
} catch (err) {
return false
}
}
/**
* stage all files in working directory
*/
addAll(dirPathArg: string) {
let done = q.defer()
plugins.shelljs.exec(`(cd ${dirPathArg} && git add -A && git status)`)
done.resolve(dirPathArg)
return done.promise
};
/**
* add a remote to the GitRepo
*/
remoteAdd(remoteNameArg: string, remoteLinkArg: string) {
let done = q.defer()
if (!remoteNameArg) {
let err = new Error('smartgit.remote.add expects a valid remote name')
plugins.beautylog.error(err.message)
done.reject(err)
return done.promise
};
if (!remoteLinkArg) {
let err = new Error()
plugins.beautylog.error(err.message)
done.reject(err)
return done.promise
};
// if everything is all right proceed
plugins.shelljs.exec(`cd ${this.repoBase} && git remote add ${remoteNameArg} ${remoteLinkArg}`)
done.resolve()
return done.promise
}
/**
* list remotes for a Gip
*/
remoteList(dirPathArg) {
let done = q.defer()
let remotes = {}
plugins.shelljs.exec(`cd ${dirPathArg} && git remote -v`)
done.resolve(remotes)
return done.promise
};
/**
* remove remote
*/
remoteRemove(dirPathArg: string) {
let done = q.defer()
return done.promise
}
/**
* commit all files that are currently staged
*/
commit(commitMessage: string) {
let done = q.defer()
plugins.shelljs.exec(`(cd ${this.repoBase} && git commit -m "${commitMessage}")`)
done.resolve()
return done.promise
}
/**
* pull latest changes from remote
*/
pull(sourceArg: string = '', branchArg: string = '') {
let done = q.defer()
// if everything is allright proceed
plugins.shelljs.exec(`(cd ${this.repoBase} && git pull ${sourceArg} ${branchArg})`)
done.resolve()
return done.promise
}
/**
* push new commits to remote
*/
push(remoteNameArg: string = '', remoteBranchArg: string = '') {
let done = q.defer()
// if everything seems allright proceed
plugins.shelljs.exec(`(cd ${this.repoBase} && git push ${remoteNameArg} ${remoteBranchArg})`)
done.resolve()
return done.promise
}
/**
* sync
*/
sync() {
this.pull().then(() => {
this.push()
})
}
/**
* get the current status
*/
status() {
let done = q.defer()
plugins.shelljs.exec(`(cd ${this.repoBase} && git status)`)
done.resolve()
return done.promise
}
}
// STATIC
/**
* creates a new GitRepo Instance after cloning a project
*/
export let createRepoFromClone = (fromArg: string, toArg: string) => {
let done = q.defer<GitRepo>()
plugins.smartfile.fs.ensureDir(toArg)
plugins.shelljs.exec(`git clone ${fromArg} ${toArg}`)
let newRepo = new GitRepo(toArg)
done.resolve(newRepo)
return done.promise
public static async createRepoFromClone(fromArg: string, toArg: string): Promise<GitRepo> {
return new GitRepo();
}
/**
* creates a new GitRepo instance after initializing a new Git Repository
*/
export let createRepoFromInit = (destinationDirArg: string) => {
let done = q.defer<GitRepo>()
plugins.smartfile.fs.ensureDir(destinationDirArg)
plugins.shelljs.exec(`cd destinationDirArg && git init`)
let newRepo = new GitRepo(destinationDirArg)
done.resolve(newRepo)
public static async createRepoFromInit(destinationDirArg: string): Promise<GitRepo> {
return new GitRepo();
}
// INSTANCE
nodegitRepo;
}

View File

@ -1,7 +1,16 @@
import 'typings-global'
export import path = require('path')
export import beautylog = require('beautylog')
export import shelljs = require('shelljs')
export import smartfile = require('smartfile')
export import smartpath = require('smartpath')
export import smartstring = require('smartstring')
// node native
import * as path from 'path';
export { path };
import * as smartfile from '@pushrocks/smartfile';
import * as smartpath from '@pushrocks/smartpath';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartstring from '@pushrocks/smartstring';
export { smartfile, smartpath, smartpromise, smartstring };
// third party
import * as nodegit from 'nodegit';
export { nodegit };

View File

@ -1,3 +1,17 @@
{
"extends": "tslint-config-standard"
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}