Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
5944c7e96f | |||
39ea160fdf | |||
91ca5e53f1 | |||
778267bb36 | |||
61407e4854 | |||
2771413723 | |||
b83752a98a | |||
48f71ed1c2 |
22213
package-lock.json
generated
22213
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
29
package.json
29
package.json
@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartgit",
|
"name": "@pushrocks/smartgit",
|
||||||
"version": "1.0.17",
|
"version": "2.0.2",
|
||||||
"description": "smart wrapper for nodegit",
|
"description": "smart wrapper for nodegit",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -24,21 +25,19 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartgit",
|
"homepage": "https://gitlab.com/pushrocks/smartgit",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^8.0.0",
|
"@pushrocks/smartenv": "^5.0.2",
|
||||||
"@pushrocks/smartpath": "^4.0.3",
|
"@pushrocks/smartfile": "^10.0.4",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpath": "^5.0.5",
|
||||||
"@pushrocks/smartshell": "^2.0.26",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smartstring": "^3.0.18",
|
"@pushrocks/smartshell": "^2.0.30",
|
||||||
"@types/minimatch": "^3.0.3",
|
"@pushrocks/smartstring": "^4.0.2",
|
||||||
"@types/nodegit": "^0.26.7",
|
"@types/minimatch": "^3.0.5",
|
||||||
"nodegit": "^0.27.0"
|
"isomorphic-git": "^1.19.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.63",
|
||||||
"@gitzone/tstest": "^1.0.44",
|
"@gitzone/tstest": "^1.0.72",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^5.0.4"
|
||||||
"tslint": "^6.1.3",
|
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"private": false,
|
"private": false,
|
||||||
"files": [
|
"files": [
|
||||||
|
18
test/test.ts
18
test/test.ts
@ -1,12 +1,26 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import * as smartgit from '../ts/index';
|
import * as smartgit from '../ts/index.js';
|
||||||
|
|
||||||
|
import * as smartpath from '@pushrocks/smartpath';
|
||||||
|
const __dirname = smartpath.get.dirnameFromImportMetaUrl(import.meta.url);
|
||||||
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).toBeInstanceOf(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();
|
||||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@pushrocks/smartgit',
|
||||||
|
version: '2.0.2',
|
||||||
|
description: 'smart wrapper for nodegit'
|
||||||
|
}
|
@ -1,3 +1,2 @@
|
|||||||
import plugins = require('./smartgit.plugins');
|
export * from './smartgit.classes.gitrepo.js';
|
||||||
|
export * from './smartgit.classes.smartgit.js';
|
||||||
export * from './smartgit.classes.gitrepo';
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import * as plugins from './smartgit.plugins';
|
import * as plugins from './smartgit.plugins.js';
|
||||||
|
|
||||||
|
import { Smartgit } from './smartgit.classes.smartgit.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 =
|
||||||
|
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;
|
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.js';
|
||||||
|
import { GitRepo } from './smartgit.classes.gitrepo.js';
|
||||||
|
|
||||||
|
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 = await this.smartenvInstance.getSafeNodeModule('fs');
|
||||||
|
this.envDeps.http = await this.smartenvInstance.getSafeNodeModule('isomorphic-git/http/node/index.js');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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 };
|
||||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"esModuleInterop": true
|
||||||
|
}
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"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"
|
|
||||||
}
|
|
Reference in New Issue
Block a user