|
|
@ -19,10 +19,12 @@ import { Octokit, App } from "octokit" |
|
|
|
import { OctokitResponse } from '@octokit/types' |
|
|
|
import { OctokitResponse } from '@octokit/types' |
|
|
|
import { Endpoints } from "@octokit/types" |
|
|
|
import { Endpoints } from "@octokit/types" |
|
|
|
import { IndexedDBStorage } from './filesystems/indexedDB' |
|
|
|
import { IndexedDBStorage } from './filesystems/indexedDB' |
|
|
|
import { GitHubUser, branch, commitChange, remote, pagedCommits, remoteCommitsInputType, cloneInputType, fetchInputType, pullInputType, pushInputType, currentBranchInput, branchInputType, addInput, rmInput, resolveRefInput, readBlobInput, repositoriesInput, commitInput, branchDifference, compareBranchesInput, initInput, userEmails, checkoutInput } from '@remix-ui/git' |
|
|
|
import { GitHubUser, branch, commitChange, remote, userEmails } from '@remix-ui/git' |
|
|
|
|
|
|
|
import { checkoutInputType, statusInput, logInputType, author, pagedCommits, remoteCommitsInputType, cloneInputType, fetchInputType, pullInputType, pushInputType, currentBranchInput, branchInputType, addInputType, rmInputType, resolveRefInput, readBlobInput, repositoriesInput, commitInputType, branchDifference, compareBranchesInput, initInputType} from '@remix-api' |
|
|
|
import { LibraryProfile, StatusEvents } from '@remixproject/plugin-utils' |
|
|
|
import { LibraryProfile, StatusEvents } from '@remixproject/plugin-utils' |
|
|
|
import { ITerminal } from '@remixproject/plugin-api/src/lib/terminal' |
|
|
|
import { ITerminal } from '@remixproject/plugin-api/src/lib/terminal' |
|
|
|
import { partial } from 'lodash' |
|
|
|
import { partial } from 'lodash' |
|
|
|
|
|
|
|
import { CustomRemixApi } from '@remix-api' |
|
|
|
|
|
|
|
|
|
|
|
declare global { |
|
|
|
declare global { |
|
|
|
interface Window { remixFileSystemCallback: IndexedDBStorage; remixFileSystem: any; } |
|
|
|
interface Window { remixFileSystemCallback: IndexedDBStorage; remixFileSystem: any; } |
|
|
@ -34,11 +36,11 @@ const profile: LibraryProfile = { |
|
|
|
description: 'Decentralized git provider', |
|
|
|
description: 'Decentralized git provider', |
|
|
|
icon: 'assets/img/fileManager.webp', |
|
|
|
icon: 'assets/img/fileManager.webp', |
|
|
|
version: '0.0.1', |
|
|
|
version: '0.0.1', |
|
|
|
methods: ['init', 'localStorageUsed', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'export', 'import', 'status', 'log', 'commit', 'add', 'remove', 'reset', 'rm', 'lsfiles', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pull', 'setIpfsConfig', 'zip', 'setItem', 'getItem', 'version', 'updateSubmodules' |
|
|
|
methods: ['init', 'localStorageUsed', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'export', 'import', 'status', 'log', 'commit', 'add', 'remove', 'rm', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pull', 'setIpfsConfig', 'zip', 'setItem', 'getItem', 'version', 'updateSubmodules' |
|
|
|
, 'getGitHubUser', 'remotebranches', 'remotecommits', 'repositories', 'getCommitChanges', 'compareBranches'], |
|
|
|
, 'getGitHubUser', 'remotebranches', 'remotecommits', 'repositories', 'getCommitChanges', 'compareBranches'], |
|
|
|
kind: 'file-system' |
|
|
|
kind: 'file-system' |
|
|
|
} |
|
|
|
} |
|
|
|
class DGitProvider extends Plugin { |
|
|
|
class DGitProvider extends Plugin<any, CustomRemixApi> { |
|
|
|
ipfsconfig: { host: string; port: number; protocol: string; ipfsurl: string } |
|
|
|
ipfsconfig: { host: string; port: number; protocol: string; ipfsurl: string } |
|
|
|
globalIPFSConfig: { host: string; port: number; protocol: string; ipfsurl: string } |
|
|
|
globalIPFSConfig: { host: string; port: number; protocol: string; ipfsurl: string } |
|
|
|
remixIPFS: { host: string; port: number; protocol: string; ipfsurl: string } |
|
|
|
remixIPFS: { host: string; port: number; protocol: string; ipfsurl: string } |
|
|
@ -141,7 +143,7 @@ class DGitProvider extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async getCommandUser(input) { |
|
|
|
async getCommandUser(input) { |
|
|
|
const author = { |
|
|
|
const author: author = { |
|
|
|
name: '', |
|
|
|
name: '', |
|
|
|
email: '' |
|
|
|
email: '' |
|
|
|
} |
|
|
|
} |
|
|
@ -167,7 +169,7 @@ class DGitProvider extends Plugin { |
|
|
|
return author |
|
|
|
return author |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async init(input?: initInput): Promise<void> { |
|
|
|
async init(input?: initInputType): Promise<void> { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
await this.call('isogit', 'init', { |
|
|
|
await this.call('isogit', 'init', { |
|
|
|
defaultBranch: (input && input.defaultBranch) || 'main' |
|
|
|
defaultBranch: (input && input.defaultBranch) || 'main' |
|
|
@ -192,7 +194,7 @@ class DGitProvider extends Plugin { |
|
|
|
return version |
|
|
|
return version |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async status(cmd): Promise<Array<StatusRow>> { |
|
|
|
async status(cmd: statusInput): Promise<Array<StatusRow>> { |
|
|
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
const status = await this.call('isogit', 'status', cmd) |
|
|
|
const status = await this.call('isogit', 'status', cmd) |
|
|
@ -208,7 +210,7 @@ class DGitProvider extends Plugin { |
|
|
|
return status |
|
|
|
return status |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async add(cmd: addInput): Promise<void> { |
|
|
|
async add(cmd: addInputType): Promise<void> { |
|
|
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
await this.call('isogit', 'add', cmd) |
|
|
|
await this.call('isogit', 'add', cmd) |
|
|
@ -222,7 +224,7 @@ class DGitProvider extends Plugin { |
|
|
|
this.emit('add') |
|
|
|
this.emit('add') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async rm(cmd: rmInput) { |
|
|
|
async rm(cmd: rmInputType) { |
|
|
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
await this.call('isogit', 'rm', cmd) |
|
|
|
await this.call('isogit', 'rm', cmd) |
|
|
@ -236,21 +238,7 @@ class DGitProvider extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async reset(cmd) { |
|
|
|
async checkout(cmd: checkoutInputType): Promise<void> { |
|
|
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
|
|
|
|
await this.call('isogit', 'reset', cmd) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
await git.resetIndex({ |
|
|
|
|
|
|
|
...await this.addIsomorphicGitConfigFS(), |
|
|
|
|
|
|
|
...cmd |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
this.emit('rm') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async checkout(cmd: checkoutInput): Promise<void> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
await this.call('isogit', 'checkout', cmd) |
|
|
|
await this.call('isogit', 'checkout', cmd) |
|
|
@ -291,12 +279,11 @@ class DGitProvider extends Plugin { |
|
|
|
this.emit('checkout') |
|
|
|
this.emit('checkout') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async log(cmd: { ref: string }): Promise<ReadCommitResult[]> { |
|
|
|
async log(cmd: logInputType): Promise<ReadCommitResult[]> { |
|
|
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
const status = await this.call('isogit', 'log', { |
|
|
|
const status = await this.call('isogit', 'log', { |
|
|
|
...cmd, |
|
|
|
...cmd, |
|
|
|
depth: 10 |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return status |
|
|
|
return status |
|
|
@ -310,6 +297,9 @@ class DGitProvider extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async compareBranches({ branch, remote }: compareBranchesInput): Promise<branchDifference> { |
|
|
|
async compareBranches({ branch, remote }: compareBranchesInput): Promise<branchDifference> { |
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
|
|
|
|
return await this.call('isogit', 'compareBranches', { branch, remote }) |
|
|
|
|
|
|
|
} |
|
|
|
// Get current branch commits
|
|
|
|
// Get current branch commits
|
|
|
|
const headCommits = await git.log({ |
|
|
|
const headCommits = await git.log({ |
|
|
|
...await this.addIsomorphicGitConfigFS(), |
|
|
|
...await this.addIsomorphicGitConfigFS(), |
|
|
@ -339,6 +329,11 @@ class DGitProvider extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async getCommitChanges(commitHash1: string, commitHash2: string): Promise<commitChange[]> { |
|
|
|
async getCommitChanges(commitHash1: string, commitHash2: string): Promise<commitChange[]> { |
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
|
|
|
|
const result = this.call('isogit', 'getCommitChanges', commitHash1, commitHash2 ) |
|
|
|
|
|
|
|
return result |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const result: commitChange[] = await git.walk({ |
|
|
|
const result: commitChange[] = await git.walk({ |
|
|
|
...await this.addIsomorphicGitConfigFS(), |
|
|
|
...await this.addIsomorphicGitConfigFS(), |
|
|
|
trees: [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })], |
|
|
|
trees: [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })], |
|
|
@ -388,14 +383,14 @@ class DGitProvider extends Plugin { |
|
|
|
return result |
|
|
|
return result |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async remotes(config): Promise<remote[]> { |
|
|
|
async remotes(): Promise<remote[]> { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
return await this.call('isogit', 'remotes', config) |
|
|
|
return await this.call('isogit', 'remotes') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let remotes: remote[] = [] |
|
|
|
let remotes: remote[] = [] |
|
|
|
try { |
|
|
|
try { |
|
|
|
remotes = (await git.listRemotes({ ...config ? config : await this.addIsomorphicGitConfigFS() })).map((remote) => { return { name: remote.remote, url: remote.url } } |
|
|
|
remotes = (await git.listRemotes({ ...await this.addIsomorphicGitConfigFS() })).map((remote) => { return { name: remote.remote, url: remote.url } } |
|
|
|
) |
|
|
|
) |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
// do nothing
|
|
|
|
// do nothing
|
|
|
@ -423,15 +418,15 @@ class DGitProvider extends Plugin { |
|
|
|
return status |
|
|
|
return status |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async currentbranch(config: currentBranchInput): Promise<branch> { |
|
|
|
async currentbranch(input: currentBranchInput): Promise<branch> { |
|
|
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
return await this.call('isogit', 'currentbranch') |
|
|
|
return await this.call('isogit', 'currentbranch', input) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
const defaultConfig = await this.addIsomorphicGitConfigFS() |
|
|
|
const defaultConfig = await this.addIsomorphicGitConfigFS() |
|
|
|
const cmd = config ? defaultConfig ? { ...defaultConfig, ...config } : config : defaultConfig |
|
|
|
const cmd = input ? defaultConfig ? { ...defaultConfig, ...input } : input : defaultConfig |
|
|
|
const name = await git.currentBranch(cmd) |
|
|
|
const name = await git.currentBranch(cmd) |
|
|
|
let remote: remote = undefined |
|
|
|
let remote: remote = undefined |
|
|
|
try { |
|
|
|
try { |
|
|
@ -463,13 +458,15 @@ class DGitProvider extends Plugin { |
|
|
|
async branches(config): Promise<branch[]> { |
|
|
|
async branches(config): Promise<branch[]> { |
|
|
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
return await this.call('isogit', 'branches') |
|
|
|
const branches = await this.call('isogit', 'branches') |
|
|
|
|
|
|
|
console.log(branches) |
|
|
|
|
|
|
|
return branches |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
const defaultConfig = await this.addIsomorphicGitConfigFS() |
|
|
|
const defaultConfig = await this.addIsomorphicGitConfigFS() |
|
|
|
const cmd = config ? defaultConfig ? { ...defaultConfig, ...config } : config : defaultConfig |
|
|
|
const cmd = config ? defaultConfig ? { ...defaultConfig, ...config } : config : defaultConfig |
|
|
|
const remotes = await this.remotes(config) |
|
|
|
const remotes = await this.remotes() |
|
|
|
let branches: branch[] = [] |
|
|
|
let branches: branch[] = [] |
|
|
|
branches = (await git.listBranches(cmd)).map((branch) => { return { remote: undefined, name: branch } }) |
|
|
|
branches = (await git.listBranches(cmd)).map((branch) => { return { remote: undefined, name: branch } }) |
|
|
|
for (const remote of remotes) { |
|
|
|
for (const remote of remotes) { |
|
|
@ -484,7 +481,7 @@ class DGitProvider extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async commit(cmd: commitInput): Promise<string> { |
|
|
|
async commit(cmd: commitInputType): Promise<string> { |
|
|
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
try { |
|
|
|
try { |
|
|
@ -511,19 +508,6 @@ class DGitProvider extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async lsfiles(cmd) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
|
|
|
|
return await this.call('isogit', 'lsfiles', cmd) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filesInStaging = await git.listFiles({ |
|
|
|
|
|
|
|
...await this.addIsomorphicGitConfigFS(), |
|
|
|
|
|
|
|
...cmd |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return filesInStaging |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async resolveref(cmd: resolveRefInput): Promise<string> { |
|
|
|
async resolveref(cmd: resolveRefInput): Promise<string> { |
|
|
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
@ -569,7 +553,7 @@ class DGitProvider extends Plugin { |
|
|
|
|
|
|
|
|
|
|
|
async addremote(input: remote): Promise<void> { |
|
|
|
async addremote(input: remote): Promise<void> { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
await this.call('isogit', 'addremote', { url: input.url, remote: input.name }) |
|
|
|
await this.call('isogit', 'addremote', input) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
await git.addRemote({ ...await this.addIsomorphicGitConfigFS(), url: input.url, remote: input.name }) |
|
|
|
await git.addRemote({ ...await this.addIsomorphicGitConfigFS(), url: input.url, remote: input.name }) |
|
|
@ -577,7 +561,7 @@ class DGitProvider extends Plugin { |
|
|
|
|
|
|
|
|
|
|
|
async delremote(input: remote) { |
|
|
|
async delremote(input: remote) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
await this.call('isogit', 'delremote', { remote: input.name }) |
|
|
|
await this.call('isogit', 'delremote', input) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
await git.deleteRemote({ ...await this.addIsomorphicGitConfigFS(), remote: input.name }) |
|
|
|
await git.deleteRemote({ ...await this.addIsomorphicGitConfigFS(), remote: input.name }) |
|
|
@ -608,6 +592,7 @@ class DGitProvider extends Plugin { |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
this.call('notification', 'alert', { |
|
|
|
this.call('notification', 'alert', { |
|
|
|
id: 'dgitAlert', |
|
|
|
id: 'dgitAlert', |
|
|
|
|
|
|
|
title: 'Error Cloning', |
|
|
|
message: 'Unexpected error while cloning the repository: \n' + e.toString(), |
|
|
|
message: 'Unexpected error while cloning the repository: \n' + e.toString(), |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
@ -791,7 +776,10 @@ class DGitProvider extends Plugin { |
|
|
|
input, |
|
|
|
input, |
|
|
|
} |
|
|
|
} |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
return await this.call('isogit', 'push', cmd) |
|
|
|
return await this.call('isogit', 'push', { |
|
|
|
|
|
|
|
...input, |
|
|
|
|
|
|
|
author: await this.getCommandUser(input), |
|
|
|
|
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
const cmd2 = { |
|
|
|
const cmd2 = { |
|
|
@ -820,7 +808,10 @@ class DGitProvider extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
let result |
|
|
|
let result |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
result = await this.call('isogit', 'pull', cmd) |
|
|
|
result = await this.call('isogit', 'pull', { |
|
|
|
|
|
|
|
...input, |
|
|
|
|
|
|
|
author: await this.getCommandUser(input), |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
const cmd2 = { |
|
|
|
const cmd2 = { |
|
|
@ -852,7 +843,10 @@ class DGitProvider extends Plugin { |
|
|
|
|
|
|
|
|
|
|
|
let result |
|
|
|
let result |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
result = await this.call('isogit', 'fetch', cmd) |
|
|
|
result = await this.call('isogit', 'fetch', { |
|
|
|
|
|
|
|
...input, |
|
|
|
|
|
|
|
author: await this.getCommandUser(input), |
|
|
|
|
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const cmd2 = { |
|
|
|
const cmd2 = { |
|
|
|
...cmd, |
|
|
|
...cmd, |
|
|
@ -1072,6 +1066,7 @@ class DGitProvider extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async remotecommits(input: remoteCommitsInputType): Promise<pagedCommits[]> { |
|
|
|
async remotecommits(input: remoteCommitsInputType): Promise<pagedCommits[]> { |
|
|
|
|
|
|
|
console.log('remotecommits', input) |
|
|
|
const octokit = new Octokit({ |
|
|
|
const octokit = new Octokit({ |
|
|
|
auth: input.token |
|
|
|
auth: input.token |
|
|
|
}) |
|
|
|
}) |
|
|
|