BREAKING CHANGE(dependencies): switch to isomorphic git
This commit is contained in:
parent
b83752a98a
commit
2771413723
23375
package-lock.json
generated
23375
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -24,19 +24,19 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartgit",
|
"homepage": "https://gitlab.com/pushrocks/smartgit",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^8.0.0",
|
"@pushrocks/smartenv": "^4.0.16",
|
||||||
|
"@pushrocks/smartfile": "^8.0.10",
|
||||||
"@pushrocks/smartpath": "^4.0.3",
|
"@pushrocks/smartpath": "^4.0.3",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.1.6",
|
||||||
"@pushrocks/smartshell": "^2.0.26",
|
"@pushrocks/smartshell": "^2.0.28",
|
||||||
"@pushrocks/smartstring": "^3.0.18",
|
"@pushrocks/smartstring": "^3.0.24",
|
||||||
"@types/minimatch": "^3.0.3",
|
"@types/minimatch": "^3.0.5",
|
||||||
"@types/nodegit": "^0.26.7",
|
"isomorphic-git": "^1.10.1"
|
||||||
"nodegit": "^0.27.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.28",
|
||||||
"@gitzone/tstest": "^1.0.44",
|
"@gitzone/tstest": "^1.0.59",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
|
14
test/test.ts
14
test/test.ts
@ -3,10 +3,22 @@ import * as smartgit from '../ts/index';
|
|||||||
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
|
let testSmartgitInstance: smartgit.Smartgit;
|
||||||
const testRepoDir = path.join(__dirname, '../.nogit/testrepo');
|
const testRepoDir = path.join(__dirname, '../.nogit/testrepo');
|
||||||
|
const testRepoDirSmartfile = path.join(__dirname, '../.nogit/pushrocks_smartfile')
|
||||||
|
|
||||||
|
tap.test('should create a valid smartgit instance', async () => {
|
||||||
|
testSmartgitInstance = new smartgit.Smartgit();
|
||||||
|
await testSmartgitInstance.init();
|
||||||
|
expect(testSmartgitInstance).to.be.instanceOf(smartgit.Smartgit);
|
||||||
|
})
|
||||||
|
|
||||||
tap.test('should create a new repo at .nogit', async () => {
|
tap.test('should create a new repo at .nogit', async () => {
|
||||||
const gitRepo = await smartgit.GitRepo.fromCreatingRepoInDir(testRepoDir);
|
const gitRepo = await testSmartgitInstance.createRepoByOpen(testRepoDir);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should clone a repo', async () => {
|
||||||
|
const gitRepo = await testSmartgitInstance.createRepoByClone('https://gitlab.com/pushrocks/smartfile.git', testRepoDirSmartfile);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
import plugins = require('./smartgit.plugins');
|
import plugins = require('./smartgit.plugins');
|
||||||
|
|
||||||
export * from './smartgit.classes.gitrepo';
|
export * from './smartgit.classes.gitrepo';
|
||||||
|
export * from './smartgit.classes.smartgit';
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import * as plugins from './smartgit.plugins';
|
import * as plugins from './smartgit.plugins';
|
||||||
|
|
||||||
|
import { Smartgit } from './smartgit.classes.smartgit';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class GitRepo allows access to git directories from node
|
* class GitRepo allows access to git directories from node
|
||||||
*/
|
*/
|
||||||
@ -8,39 +10,61 @@ export class GitRepo {
|
|||||||
/**
|
/**
|
||||||
* creates a new GitRepo Instance after cloning a project
|
* creates a new GitRepo Instance after cloning a project
|
||||||
*/
|
*/
|
||||||
public static async fromCloningIntoDir(fromArg: string, toArg: string): Promise<GitRepo> {
|
public static async fromCloningIntoDir(
|
||||||
|
smartgitRefArg: Smartgit,
|
||||||
|
fromArg: string,
|
||||||
|
toArg: string
|
||||||
|
): Promise<GitRepo> {
|
||||||
const dirArg = plugins.path.resolve(toArg);
|
const dirArg = plugins.path.resolve(toArg);
|
||||||
const ngRespository = await plugins.nodegit.Clone.clone(fromArg, toArg, {
|
await plugins.isomorphicGit.clone({
|
||||||
bare: 0,
|
dir: toArg,
|
||||||
checkoutBranch: 'master',
|
fs: smartgitRefArg.envDeps.fs,
|
||||||
|
http: smartgitRefArg.envDeps.http,
|
||||||
|
url: fromArg,
|
||||||
});
|
});
|
||||||
return new GitRepo(ngRespository);
|
return new GitRepo(smartgitRefArg, toArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async fromCreatingRepoInDir(dirArg: string): Promise<GitRepo> {
|
public static async fromCreatingRepoInDir(
|
||||||
|
smartgitRefArg: Smartgit,
|
||||||
|
dirArg: string
|
||||||
|
): Promise<GitRepo> {
|
||||||
dirArg = plugins.path.resolve(dirArg);
|
dirArg = plugins.path.resolve(dirArg);
|
||||||
const ngRepository = await plugins.nodegit.Repository.init(dirArg, 0);
|
await plugins.isomorphicGit.init({
|
||||||
return new GitRepo(ngRepository);
|
dir: dirArg,
|
||||||
|
fs: smartgitRefArg.envDeps.fs,
|
||||||
|
});
|
||||||
|
return new GitRepo(smartgitRefArg, dirArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async fromOpeningRepoDir(dirArg: string) {
|
public static async fromOpeningRepoDir(smartgitRefArg: Smartgit, dirArg: string) {
|
||||||
dirArg = plugins.path.resolve(dirArg);
|
dirArg = plugins.path.resolve(dirArg);
|
||||||
const ngRepository = await plugins.nodegit.Repository.open(dirArg);
|
return new GitRepo(smartgitRefArg, dirArg);
|
||||||
return new GitRepo(ngRepository);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
public nodegitRepo: plugins.nodegit.Repository;
|
public smartgitRef: Smartgit;
|
||||||
|
public repoDir: string;
|
||||||
|
|
||||||
constructor(nodegitRepoArg: plugins.nodegit.Repository) {
|
constructor(smartgitRefArg: Smartgit, repoDirArg: string) {
|
||||||
this.nodegitRepo = nodegitRepoArg;
|
this.smartgitRef = smartgitRefArg;
|
||||||
|
this.repoDir = repoDirArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lists remotes
|
* lists remotes
|
||||||
*/
|
*/
|
||||||
public async listRemotes(): Promise<plugins.nodegit.Remote[]> {
|
public async listRemotes(): Promise<
|
||||||
return this.nodegitRepo.getRemotes();
|
{
|
||||||
|
remote: string;
|
||||||
|
url: string;
|
||||||
|
}[]
|
||||||
|
> {
|
||||||
|
const remotes = await plugins.isomorphicGit.listRemotes({
|
||||||
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
|
dir: this.repoDir,
|
||||||
|
});
|
||||||
|
return remotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,31 +73,42 @@ export class GitRepo {
|
|||||||
* @param remoteUrlArg
|
* @param remoteUrlArg
|
||||||
*/
|
*/
|
||||||
public async ensureRemote(remoteNameArg: string, remoteUrlArg: string): Promise<void> {
|
public async ensureRemote(remoteNameArg: string, remoteUrlArg: string): Promise<void> {
|
||||||
const existingUrl = await this.getUrlForRemote(remoteNameArg);
|
const remotes = await this.listRemotes();
|
||||||
if (existingUrl === remoteUrlArg) {
|
const existingRemote =
|
||||||
return;
|
remotes.find((itemArg) => itemArg.remote === remoteNameArg);
|
||||||
|
if (existingRemote) {
|
||||||
|
if (existingRemote.url !== remoteUrlArg) {
|
||||||
|
await plugins.isomorphicGit.deleteRemote({
|
||||||
|
remote: remoteNameArg,
|
||||||
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
|
dir: this.repoDir
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (existingUrl) {
|
await plugins.isomorphicGit.addRemote({
|
||||||
await plugins.nodegit.Remote.delete(this.nodegitRepo, remoteNameArg);
|
remote: remoteNameArg,
|
||||||
}
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
await plugins.nodegit.Remote.create(this.nodegitRepo, remoteNameArg, remoteUrlArg);
|
url: remoteUrlArg
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the url for a specific remote
|
* gets the url for a specific remote
|
||||||
*/
|
*/
|
||||||
public async getUrlForRemote(remoteName: string): Promise<string> {
|
public async getUrlForRemote(remoteName: string): Promise<string> {
|
||||||
const ngRemote = await this.nodegitRepo.getRemote(remoteName);
|
const remotes = await this.listRemotes();
|
||||||
if (ngRemote) {
|
const existingRemote = remotes.find(remoteArg => remoteArg.remote === remoteName);
|
||||||
return ngRemote.url();
|
return existingRemote?.url;
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async pushBranchToRemote(branchName: string, remoteName: string) {
|
public async pushBranchToRemote(branchName: string, remoteName: string) {
|
||||||
await this.nodegitRepo.checkoutBranch(branchName);
|
await plugins.isomorphicGit.push({
|
||||||
const ngRemote = await this.nodegitRepo.getRemote(remoteName);
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
ngRemote.push([branchName]);
|
http: this.smartgitRef.envDeps.http,
|
||||||
|
ref: branchName,
|
||||||
|
remote: remoteName
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
36
ts/smartgit.classes.smartgit.ts
Normal file
36
ts/smartgit.classes.smartgit.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import * as plugins from './smartgit.plugins';
|
||||||
|
import { GitRepo } from './smartgit.classes.gitrepo';
|
||||||
|
|
||||||
|
export class Smartgit {
|
||||||
|
public smartenvInstance = new plugins.smartenv.Smartenv();
|
||||||
|
public envDeps: {
|
||||||
|
fs: any;
|
||||||
|
http: any;
|
||||||
|
} = {
|
||||||
|
fs: null,
|
||||||
|
http: null
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {};
|
||||||
|
|
||||||
|
public async init() {
|
||||||
|
if (this.smartenvInstance.isNode) {
|
||||||
|
this.envDeps.fs = this.smartenvInstance.getSafeNodeModule('fs');
|
||||||
|
this.envDeps.http = this.smartenvInstance.getSafeNodeModule('isomorphic-git/http/node');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public async createRepoByClone(fromUrlArg: string, toDirArg: string) {
|
||||||
|
const repo = await GitRepo.fromCloningIntoDir(this, fromUrlArg, toDirArg)
|
||||||
|
};
|
||||||
|
|
||||||
|
public async createRepoByInit(dirArg: string) {
|
||||||
|
const repo = await GitRepo.fromCreatingRepoInDir(this, dirArg);
|
||||||
|
return repo;
|
||||||
|
};
|
||||||
|
|
||||||
|
public async createRepoByOpen(dirArg: string) {
|
||||||
|
const repo = await GitRepo.fromOpeningRepoDir(this, dirArg);
|
||||||
|
return repo;
|
||||||
|
}
|
||||||
|
}
|
@ -3,14 +3,15 @@ import * as path from 'path';
|
|||||||
|
|
||||||
export { path };
|
export { path };
|
||||||
|
|
||||||
|
import * as smartenv from '@pushrocks/smartenv';
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
import * as smartpath from '@pushrocks/smartpath';
|
import * as smartpath from '@pushrocks/smartpath';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartstring from '@pushrocks/smartstring';
|
import * as smartstring from '@pushrocks/smartstring';
|
||||||
|
|
||||||
export { smartfile, smartpath, smartpromise, smartstring };
|
export { smartenv, smartfile, smartpath, smartpromise, smartstring };
|
||||||
|
|
||||||
// third party
|
// third party
|
||||||
import nodegit from 'nodegit';
|
import isomorphicGit from 'isomorphic-git';
|
||||||
|
|
||||||
export { nodegit };
|
export { isomorphicGit };
|
||||||
|
Loading…
Reference in New Issue
Block a user