refactoring

pull/4791/head
bunsenstraat 7 months ago
parent 12c587ff57
commit c0357ae03e
  1. 2
      apps/remix-ide-e2e/src/tests/plugin_api.ts
  2. 96
      apps/remix-ide/src/app/files/dgitProvider.ts
  3. 2
      apps/remix-ide/src/app/plugins/git.tsx
  4. 2
      apps/remix-ide/src/remixAppManager.js
  5. 2
      apps/remix-ide/src/remixEngine.js
  6. 14
      apps/remixdesktop/src/plugins/isoGitPlugin.ts
  7. 9
      apps/remixdesktop/src/types/index.ts
  8. 7
      apps/vyper/src/app/utils/remix-client.tsx
  9. 22
      libs/remix-ui/git/src/components/buttons/sourcecontrolbuttons.tsx
  10. 41
      libs/remix-ui/git/src/components/panels/commands/pushpull.tsx
  11. 9
      libs/remix-ui/git/src/components/panels/commits.tsx
  12. 8
      libs/remix-ui/git/src/components/panels/sourcecontrol/sourcontrolitembuttons.tsx
  13. 212
      libs/remix-ui/git/src/lib/gitactions.ts
  14. 42
      libs/remix-ui/git/src/lib/listeners.ts
  15. 16
      libs/remix-ui/git/src/state/context.tsx
  16. 4
      libs/remix-ui/git/src/state/gitpayload.ts
  17. 160
      libs/remix-ui/git/src/types/index.ts
  18. 2
      libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx
  19. 3
      libs/remix-ui/workspace/src/lib/actions/payload.ts
  20. 77
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  21. 7
      libs/remix-ui/workspace/src/lib/contexts/index.ts
  22. 7
      libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx
  23. 8
      libs/remix-ui/workspace/src/lib/reducers/workspace.ts
  24. 12
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx
  25. 19
      libs/remix-ui/workspace/src/lib/types/index.ts

@ -10,7 +10,7 @@ declare global {
const localPluginData: Profile & LocationProfile & ExternalProfile = { const localPluginData: Profile & LocationProfile & ExternalProfile = {
name: 'localPlugin', name: 'localPlugin',
displayName: 'Local Plugin', displayName: 'Local Plugin',
canActivate: ['dGitProvider', 'flattener', 'solidityUnitTesting', 'udapp', 'hardhat-provider'], canActivate: ['dgitApi', 'flattener', 'solidityUnitTesting', 'udapp', 'hardhat-provider'],
url: 'http://localhost:9999', url: 'http://localhost:9999',
location: 'sidePanel' location: 'sidePanel'
} }

@ -3,7 +3,7 @@
import { import {
Plugin Plugin
} from '@remixproject/engine' } from '@remixproject/engine'
import git, { ReadCommitResult } from 'isomorphic-git' import git, { ReadBlobResult, ReadCommitResult, StatusRow } from 'isomorphic-git'
import IpfsHttpClient from 'ipfs-http-client' import IpfsHttpClient from 'ipfs-http-client'
import { import {
saveAs saveAs
@ -19,7 +19,7 @@ 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, RateLimit, branch, commitChange, remote, pagedCommits } from '@remix-ui/git' import { GitHubUser, RateLimit, branch, commitChange, remote, pagedCommits, remoteCommitsInputType, cloneInputType, fetchInputType, pullInputType, pushInputType, currentBranchInput, branchInputType, addInput, rmInput, resolveRefInput, readBlobInput, repositoriesInput, commitInput, branchDifference, compareBranchesInput, initInput } from '@remix-ui/git'
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'
@ -28,7 +28,7 @@ declare global {
} }
const profile: LibraryProfile = { const profile: LibraryProfile = {
name: 'dGitProvider', name: 'dgitApi',
displayName: 'Decentralized git', displayName: 'Decentralized git',
description: 'Decentralized git provider', description: 'Decentralized git provider',
icon: 'assets/img/fileManager.webp', icon: 'assets/img/fileManager.webp',
@ -128,10 +128,10 @@ class DGitProvider extends Plugin {
return author return author
} }
async init(input?) { async init(input?: initInput): 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.branch) || 'main' defaultBranch: (input && input.defaultBranch) || 'main'
}) })
this.emit('init') this.emit('init')
return return
@ -139,7 +139,7 @@ class DGitProvider extends Plugin {
await git.init({ await git.init({
...await this.addIsomorphicGitConfigFS(), ...await this.addIsomorphicGitConfigFS(),
defaultBranch: (input && input.branch) || 'main' defaultBranch: (input && input.defaultBranch) || 'main'
}) })
this.emit('init') this.emit('init')
} }
@ -153,7 +153,7 @@ class DGitProvider extends Plugin {
return version return version
} }
async status(cmd) { async status(cmd): 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)
@ -169,7 +169,7 @@ class DGitProvider extends Plugin {
return status return status
} }
async add(cmd) { async add(cmd: addInput): 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)
@ -183,7 +183,7 @@ class DGitProvider extends Plugin {
this.emit('add') this.emit('add')
} }
async rm(cmd) { async rm(cmd: rmInput) {
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)
@ -252,7 +252,7 @@ class DGitProvider extends Plugin {
this.emit('checkout') this.emit('checkout')
} }
async log(cmd) { async log(cmd:{ref:string}):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', {
@ -270,7 +270,7 @@ class DGitProvider extends Plugin {
return status return status
} }
async compareBranches({ branch, remote }: { branch: branch, remote: remote }) { async compareBranches({ branch, remote }: compareBranchesInput): Promise<branchDifference> {
// Get current branch commits // Get current branch commits
const headCommits = await git.log({ const headCommits = await git.log({
...await this.addIsomorphicGitConfigFS(), ...await this.addIsomorphicGitConfigFS(),
@ -280,7 +280,7 @@ class DGitProvider extends Plugin {
// Get remote branch commits // Get remote branch commits
const remoteCommits = await git.log({ const remoteCommits = await git.log({
...await this.addIsomorphicGitConfigFS(), ...await this.addIsomorphicGitConfigFS(),
ref: `${remote.remote}/${branch.name}`, ref: `${remote.name}/${branch.name}`,
}); });
// Convert arrays of commit objects to sets of commit SHAs // Convert arrays of commit objects to sets of commit SHAs
@ -299,7 +299,7 @@ class DGitProvider extends Plugin {
}; };
} }
async getCommitChanges(commitHash1, commitHash2): Promise<commitChange[]> { async getCommitChanges(commitHash1: string, commitHash2: string): Promise<commitChange[]> {
//console.log(commitHash1, commitHash2, [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })]) //console.log(commitHash1, commitHash2, [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })])
const result: commitChange[] = await git.walk({ const result: commitChange[] = await git.walk({
...await this.addIsomorphicGitConfigFS(), ...await this.addIsomorphicGitConfigFS(),
@ -355,21 +355,23 @@ class DGitProvider extends Plugin {
return result return result
} }
async remotes(config) { async remotes(config): 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', config)
} }
let remotes: remote[] = [] let remotes: remote[] = []
try { try {
remotes = await git.listRemotes({ ...config ? config : await this.addIsomorphicGitConfigFS() }) remotes = (await git.listRemotes({ ...config ? config : await this.addIsomorphicGitConfigFS() })).map((remote) =>
{ return { name: remote.remote, url: remote.url } }
)
} catch (e) { } catch (e) {
// do nothing // do nothing
} }
return remotes return remotes
} }
async branch(cmd, refresh = true) { async branch(cmd: branchInputType): Promise<void> {
let status let status
if ((Registry.getInstance().get('platform').api.isDesktop())) { if ((Registry.getInstance().get('platform').api.isDesktop())) {
@ -380,7 +382,7 @@ class DGitProvider extends Plugin {
...cmd ...cmd
}) })
} }
if (refresh) { if (cmd.refresh) {
setTimeout(async () => { setTimeout(async () => {
await this.call('fileManager', 'refresh') await this.call('fileManager', 'refresh')
}, 1000) }, 1000)
@ -389,7 +391,7 @@ class DGitProvider extends Plugin {
return status return status
} }
async currentbranch(config) { async currentbranch(config: 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')
@ -411,7 +413,7 @@ class DGitProvider extends Plugin {
...defaultConfig, ...defaultConfig,
path: `remote.${remoteName}.url` path: `remote.${remoteName}.url`
}) })
remote = { remote: remoteName, url: remoteUrl } remote = { name: remoteName, url: remoteUrl }
} }
} catch (e) { } catch (e) {
@ -427,7 +429,7 @@ class DGitProvider extends Plugin {
} }
} }
async branches(config) { 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') return await this.call('isogit', 'branches')
@ -440,7 +442,7 @@ class DGitProvider extends Plugin {
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) {
cmd.remote = remote.remote cmd.remote = remote.name
const remotebranches = (await git.listBranches(cmd)).map((branch) => { return { remote: remote, name: branch } }) const remotebranches = (await git.listBranches(cmd)).map((branch) => { return { remote: remote, name: branch } })
branches = [...branches, ...remotebranches] branches = [...branches, ...remotebranches]
} }
@ -450,7 +452,7 @@ class DGitProvider extends Plugin {
} }
} }
async commit(cmd) { async commit(cmd: commitInput): Promise<string> {
if ((Registry.getInstance().get('platform').api.isDesktop())) { if ((Registry.getInstance().get('platform').api.isDesktop())) {
try { try {
@ -490,7 +492,7 @@ class DGitProvider extends Plugin {
return filesInStaging return filesInStaging
} }
async resolveref(cmd) { async resolveref(cmd: resolveRefInput): Promise<string> {
if ((Registry.getInstance().get('platform').api.isDesktop())) { if ((Registry.getInstance().get('platform').api.isDesktop())) {
return await this.call('isogit', 'resolveref', cmd) return await this.call('isogit', 'resolveref', cmd)
@ -503,7 +505,7 @@ class DGitProvider extends Plugin {
return oid return oid
} }
async readblob(cmd) { async readblob(cmd: readBlobInput): Promise<ReadBlobResult> {
if ((Registry.getInstance().get('platform').api.isDesktop())) { if ((Registry.getInstance().get('platform').api.isDesktop())) {
const readBlobResult = await this.call('isogit', 'readblob', cmd) const readBlobResult = await this.call('isogit', 'readblob', cmd)
return readBlobResult return readBlobResult
@ -533,27 +535,27 @@ class DGitProvider extends Plugin {
} }
} }
async addremote(input) { 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.remote }) await this.call('isogit', 'addremote', { url: input.url, remote: input.name })
return return
} }
await git.addRemote({ ...await this.addIsomorphicGitConfigFS(), url: input.url, remote: input.remote }) await git.addRemote({ ...await this.addIsomorphicGitConfigFS(), url: input.url, remote: input.name })
} }
async delremote(input) { 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.remote }) await this.call('isogit', 'delremote', { remote: input.name })
return return
} }
await git.deleteRemote({ ...await this.addIsomorphicGitConfigFS(), remote: input.remote }) await git.deleteRemote({ ...await this.addIsomorphicGitConfigFS(), remote: input.name })
} }
async localStorageUsed() { async localStorageUsed() {
return this.calculateLocalStorage() return this.calculateLocalStorage()
} }
async clone(input, workspaceName, workspaceExists = false) { async clone(input: cloneInputType) {
if ((Registry.getInstance().get('platform').api.isDesktop())) { if ((Registry.getInstance().get('platform').api.isDesktop())) {
const folder = await this.call('fs', 'selectFolder', null, 'Select or create a folder to clone the repository in', 'Select as Repository Destination') const folder = await this.call('fs', 'selectFolder', null, 'Select or create a folder to clone the repository in', 'Select as Repository Destination')
@ -581,7 +583,7 @@ class DGitProvider extends Plugin {
const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.') const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.')
if (!permission) return false if (!permission) return false
if (parseFloat(this.calculateLocalStorage()) > 10000) throw new Error('The local storage of the browser is full.') if (parseFloat(this.calculateLocalStorage()) > 10000) throw new Error('The local storage of the browser is full.')
if (!workspaceExists) await this.call('filePanel', 'createWorkspace', workspaceName || `workspace_${Date.now()}`, true) if (!input.workspaceExists) await this.call('filePanel', 'createWorkspace', input.workspaceName || `workspace_${Date.now()}`, true)
const cmd = { const cmd = {
url: input.url, url: input.url,
singleBranch: input.singleBranch, singleBranch: input.singleBranch,
@ -592,7 +594,7 @@ class DGitProvider extends Plugin {
} }
this.call('terminal', 'logHtml', `Cloning ${input.url}...`) this.call('terminal', 'logHtml', `Cloning ${input.url}...`)
const result = await git.clone(cmd) const result = await git.clone(cmd)
if (!workspaceExists) { if (!input.workspaceExists) {
setTimeout(async () => { setTimeout(async () => {
await this.call('fileManager', 'refresh') await this.call('fileManager', 'refresh')
}, 1000) }, 1000)
@ -733,13 +735,13 @@ class DGitProvider extends Plugin {
} }
} }
async push(input) { async push(input: pushInputType) {
console.log('push input', input) console.log('push input', input)
const cmd = { const cmd = {
force: input.force, force: input.force,
ref: input.ref, ref: input.ref.name,
remoteRef: input.remoteRef, remoteRef: input.remoteRef.name,
remote: input.remote, remote: input.remote.name,
author: await this.getCommandUser(input), author: await this.getCommandUser(input),
input, input,
} }
@ -762,12 +764,12 @@ class DGitProvider extends Plugin {
} }
} }
async pull(input) { async pull(input: pullInputType) {
const cmd = { const cmd = {
ref: input.ref, ref: input.ref.name,
remoteRef: input.remoteRef, remoteRef: input.remoteRef.name,
author: await this.getCommandUser(input), author: await this.getCommandUser(input),
remote: input.remote, remote: input.remote.name,
input, input,
} }
let result let result
@ -791,12 +793,12 @@ class DGitProvider extends Plugin {
return result return result
} }
async fetch(input) { async fetch(input: fetchInputType) {
const cmd = { const cmd = {
ref: input.ref, ref: input.ref.name,
remoteRef: input.remoteRef, remoteRef: input.remoteRef.name,
author: await this.getCommandUser(input), author: await this.getCommandUser(input),
remote: input.remote, remote: input.remote.name,
depth: input.depth || 5, depth: input.depth || 5,
singleBranch: input.singleBranch, singleBranch: input.singleBranch,
relative: input.relative, relative: input.relative,
@ -1033,7 +1035,7 @@ class DGitProvider extends Plugin {
} }
} }
async remotecommits(input: { owner: string, repo: string, token: string, branch: string, length: number, page: number }): Promise<pagedCommits[]> { async remotecommits(input: remoteCommitsInputType): Promise<pagedCommits[]> {
const octokit = new Octokit({ const octokit = new Octokit({
auth: input.token auth: input.token
}) })
@ -1095,7 +1097,7 @@ class DGitProvider extends Plugin {
return pages return pages
} }
async repositories(input: { token: string, page?: number, per_page?: number }) { async repositories(input: repositoriesInput) {
const accessToken = input.token; const accessToken = input.token;

@ -22,7 +22,7 @@ export class GitPlugin extends ViewPlugin {
onDeactivation(): void { onDeactivation(): void {
this.call('fileDecorator', 'clearFileDecorators') this.call('fileDecorator', 'clearFileDecorators')
this.call('manager', 'activatePlugin', 'dGitProvider') this.call('manager', 'activatePlugin', 'dgitApi')
} }
render() { render() {

@ -35,7 +35,7 @@ let requiredModules = [ // services + layout views + system views
'pluginManager', 'pluginManager',
'tabs', 'tabs',
'udapp', 'udapp',
'dGitProvider', 'dgitApi',
'solidity', 'solidity',
'solidity-logic', 'solidity-logic',
'gistHandler', 'gistHandler',

@ -10,7 +10,7 @@ export class RemixEngine extends Engine {
setPluginOption ({ name, kind }) { setPluginOption ({ name, kind }) {
if (kind === 'provider') return { queueTimeout: 60000 * 2 } if (kind === 'provider') return { queueTimeout: 60000 * 2 }
if (name === 'LearnEth') return { queueTimeout: 60000 } if (name === 'LearnEth') return { queueTimeout: 60000 }
if (name === 'dGitProvider') return { queueTimeout: 60000 * 4 } if (name === 'dgitApi') return { queueTimeout: 60000 * 4 }
if (name === 'slither') return { queueTimeout: 60000 * 4 } // Requires when a solc version is installed if (name === 'slither') return { queueTimeout: 60000 * 4 } // Requires when a solc version is installed
if (name === 'hardhat') return { queueTimeout: 60000 * 4 } if (name === 'hardhat') return { queueTimeout: 60000 * 4 }
if (name === 'truffle') return { queueTimeout: 60000 * 4 } if (name === 'truffle') return { queueTimeout: 60000 * 4 }

@ -6,6 +6,7 @@ import git from 'isomorphic-git'
import { dialog } from "electron"; import { dialog } from "electron";
import http from 'isomorphic-git/http/web' import http from 'isomorphic-git/http/web'
import { gitProxy } from "../tools/git"; import { gitProxy } from "../tools/git";
import { remote } from "../types";
const profile: Profile = { const profile: Profile = {
name: 'isogit', name: 'isogit',
@ -328,9 +329,9 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
async clone(cmd: any) { async clone(cmd: any) {
if (this.gitIsInstalled) { if (this.gitIsInstalled) {
try{ try {
await gitProxy.clone(cmd.url, cmd.dir) await gitProxy.clone(cmd.url, cmd.dir)
}catch(e){ } catch (e) {
throw e throw e
} }
} else { } else {
@ -376,8 +377,9 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
if (!this.workingDir || this.workingDir === '') { if (!this.workingDir || this.workingDir === '') {
return [] return []
} }
let remotes = [] let remotes: remote[] = []
remotes = await git.listRemotes({ ...await this.getGitConfig() }) remotes = (await git.listRemotes({ ...await this.getGitConfig() })).map((remote) => { return { name: remote.remote, url: remote.url } }
)
return remotes return remotes
} }
@ -408,10 +410,10 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
for (const remote of remotes) { for (const remote of remotes) {
cmd = { cmd = {
...cmd, ...cmd,
remote: remote.remote remote: remote.name
} }
const remotebranches = (await git.listBranches(cmd)).map((branch) => { return { remote: remote.remote, name: branch } }) const remotebranches = (await git.listBranches(cmd)).map((branch) => { return { remote: remote.name, name: branch } })
branches = [...branches, ...remotebranches] branches = [...branches, ...remotebranches]
} }

@ -0,0 +1,9 @@
export type branch = {
name: string
remote: remote
}
export type remote = {
name: string
url: string
}

@ -81,14 +81,17 @@ export class RemixClient extends PluginClient {
try { try {
// @ts-ignore // @ts-ignore
this.call('notification', 'toast', 'cloning Snekmate Vyper repository...') this.call('notification', 'toast', 'cloning Snekmate Vyper repository...')
await this.call('manager', 'activatePlugin', 'dGitProvider')
await this.call('manager', 'activatePlugin', 'dgitApi')
/*
await this.call( await this.call(
'dGitProvider', 'dgitApi',
'clone', 'clone',
{url: 'https://github.com/pcaversaccio/snekmate', token: null, branch: 'v0.0.5'}, {url: 'https://github.com/pcaversaccio/snekmate', token: null, branch: 'v0.0.5'},
// @ts-ignore // @ts-ignore
'snekmate' 'snekmate'
) )
*/
this.call( this.call(
// @ts-ignore // @ts-ignore
'notification', 'notification',

@ -29,17 +29,29 @@ export const SourceControlButtons = () => {
} }
const pull = async () => { const pull = async () => {
await actions.pull(getRemoteName(), branch ? branch.name : context.currentBranch.name) await actions.pull({
remote: getRemote(),
ref: branch ? branch : context.currentBranch
})
} }
const push = async () => { const push = async () => {
await actions.push(getRemoteName(), branch ? branch.name : context.currentBranch.name) await actions.push({
await actions.fetch(getRemoteName(), branch ? branch.name : context.currentBranch.name, null, null, true) remote: getRemote(),
ref: branch ? branch : context.currentBranch
})
await actions.fetch({
remote: getRemote(),
ref: branch ? branch : context.currentBranch,
relative: false,
depth: 1,
singleBranch: true
})
} }
const sync = async () => { const sync = async () => {
await actions.pull(getRemoteName(), branch ? branch.name : context.currentBranch.name) await pull()
await actions.push(getRemoteName(), branch ? branch.name : context.currentBranch.name) await push()
} }
const refresh = async() => { const refresh = async() => {

@ -5,6 +5,7 @@ import { selectStyles, selectTheme } from "../../../types/styles";
import Select, { Options, OptionsOrGroups } from 'react-select' import Select, { Options, OptionsOrGroups } from 'react-select'
import GitUIButton from "../../buttons/gituibutton"; import GitUIButton from "../../buttons/gituibutton";
import { remote } from "../../../types"; import { remote } from "../../../types";
import { relative } from "path";
export const PushPull = () => { export const PushPull = () => {
const context = React.useContext(gitPluginContext) const context = React.useContext(gitPluginContext)
@ -47,12 +48,46 @@ export const PushPull = () => {
const push = async () => { const push = async () => {
console.log('PUSH', context.upstream, localBranch, remoteBranch, force) console.log('PUSH', context.upstream, localBranch, remoteBranch, force)
await actions.push(context.upstream.name, localBranch, remoteBranch, force) await actions.push({
await actions.fetch(context.upstream.name, localBranch, remoteBranch, 1, true) remote: context.upstream,
ref: {
name: localBranch,
remote: null
},
remoteRef: {
name: remoteBranch,
remote: null
},
force: force
})
await actions.fetch({
remote: context.upstream,
ref: {
name: localBranch,
remote: null
},
remoteRef: {
name: remoteBranch,
remote: null
},
depth: 1,
relative: true,
singleBranch: true
})
} }
const pull = async () => { const pull = async () => {
actions.pull(context.upstream.name, localBranch, remoteBranch) await actions.pull({
remote: context.upstream,
ref: {
name: localBranch,
remote: null
},
remoteRef: {
name: remoteBranch,
remote: null
},
})
} }
useEffect(() => { useEffect(() => {

@ -25,7 +25,14 @@ export const Commits = () => {
const loadNextPage = () => { const loadNextPage = () => {
console.log('LOAD NEXT PAGE', context.commits.length) console.log('LOAD NEXT PAGE', context.commits.length)
actions.fetch(null, context.currentBranch.name, null, 5, true, true) //actions.fetch(null, context.currentBranch.name, null, 5, true, true)
actions.fetch({
remote: null,
ref: context.currentBranch,
relative: true,
depth: 5,
singleBranch: true
})
//actions.getBranchCommits(branch, lastPageNumber+1) //actions.getBranchCommits(branch, lastPageNumber+1)
} }

@ -23,17 +23,17 @@ export const SourceControlItemButtons = (props: SourceControlItemButtonsProps) =
{status && status.indexOf("modified") === -1 ? <></> : <button onClick={async () => await actions.checkoutfile(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button>} {status && status.indexOf("modified") === -1 ? <></> : <button onClick={async () => await actions.checkoutfile(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button>}
{status && status.indexOf("deleted") === -1 ? <></> : <button onClick={async () => await actions.checkoutfile(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button>} {status && status.indexOf("deleted") === -1 ? <></> : <button onClick={async () => await actions.checkoutfile(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button>}
{status && status.indexOf("deleted") !== -1 ? <></> : <button data-id={`unStage${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.rm(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faMinus} className="" /></button>} {status && status.indexOf("deleted") !== -1 ? <></> : <button data-id={`unStage${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.rm({filepath:file.filename})} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faMinus} className="" /></button>}
</> </>
} }
if (group.name === 'Changes') { if (group.name === 'Changes') {
return <> return <>
{status && status.indexOf("deleted") === -1 ? <></> : <><button onClick={async () => await actions.checkoutfile(file.filename)} data-id={`undo${group.name}${path.basename(file.filename)}`} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button><button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.rm(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button></>} {status && status.indexOf("deleted") === -1 ? <></> : <><button onClick={async () => await actions.checkoutfile(file.filename)} data-id={`undo${group.name}${path.basename(file.filename)}`} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button><button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.rm({filepath:file.filename})} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button></>}
{status && status.indexOf("modified") === -1 ? <></> : <button onClick={async () => await actions.checkoutfile(file.filename)} data-id={`undo${group.name}${path.basename(file.filename)}`} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button>} {status && status.indexOf("modified") === -1 ? <></> : <button onClick={async () => await actions.checkoutfile(file.filename)} data-id={`undo${group.name}${path.basename(file.filename)}`} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button>}
{(status && status.indexOf("unstaged") !== -1 || status && status.indexOf("deleted") !== -1) ? <></> : <button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.add(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button>} {(status && status.indexOf("unstaged") !== -1 || status && status.indexOf("deleted") !== -1) ? <></> : <button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.add({filepath:file.filename})} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button>}
{(status && status.indexOf("unstaged") !== -1 && status && status.indexOf("modified") !== -1) ? <button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.add(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button> : <></>} {(status && status.indexOf("unstaged") !== -1 && status && status.indexOf("modified") !== -1) ? <button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.add({filepath:file.filename})} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button> : <></>}
</> </>
} }
return <></> return <></>

@ -2,7 +2,7 @@ import { ViewPlugin } from "@remixproject/engine-web";
import { ReadBlobResult, ReadCommitResult } from "isomorphic-git"; import { ReadBlobResult, ReadCommitResult } from "isomorphic-git";
import React from "react"; import React from "react";
import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRateLimit, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog } from "../state/gitpayload"; import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRateLimit, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog } from "../state/gitpayload";
import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult } from '../types'; import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult, customGitApi, customDGitSystem, cloneInputType, fetchInputType, pullInputType, pushInputType, CustomRemixApi, checkoutInput, rmInput, addInput, repository } from '../types';
import { removeSlash } from "../utils"; import { removeSlash } from "../utils";
import { disableCallBacks, enableCallBacks } from "./listeners"; import { disableCallBacks, enableCallBacks } from "./listeners";
import { AlertModal, ModalTypes } from "@remix-ui/app"; import { AlertModal, ModalTypes } from "@remix-ui/app";
@ -37,8 +37,7 @@ const statusmatrix: statusMatrixType[] = fileStatuses.map((x: any) => {
}; };
}); });
let plugin: Plugin<any, CustomRemixApi>, dispatch: React.Dispatch<gitActionDispatch>
let plugin: Plugin, dispatch: React.Dispatch<gitActionDispatch>
export const setPlugin = (p: Plugin, dispatcher: React.Dispatch<gitActionDispatch>) => { export const setPlugin = (p: Plugin, dispatcher: React.Dispatch<gitActionDispatch>) => {
plugin = p plugin = p
@ -48,13 +47,13 @@ export const setPlugin = (p: Plugin, dispatcher: React.Dispatch<gitActionDispatc
export const getBranches = async () => { export const getBranches = async () => {
console.log('getBranches') console.log('getBranches')
const branches = await plugin.call("dGitProvider", "branches"); const branches = await plugin.call('dgitApi', "branches")
console.log('branches :>>', branches) console.log('branches :>>', branches)
dispatch(setBranches(branches)); dispatch(setBranches(branches));
} }
export const getRemotes = async () => { export const getRemotes = async () => {
console.log('getRemotes') console.log('getRemotes')
const remotes: remote[] = await plugin.call("dGitProvider", "remotes" as any); const remotes: remote[] = await plugin.call('dgitApi', "remotes");
console.log('remotes :>>', remotes) console.log('remotes :>>', remotes)
dispatch(setRemotes(remotes)); dispatch(setRemotes(remotes));
} }
@ -69,7 +68,7 @@ export const getFileStatusMatrix = async (filepaths: string[]) => {
statusmatrix.map((sm) => { statusmatrix.map((sm) => {
if (JSON.stringify(sm.status) === JSON.stringify(m.status)) { if (JSON.stringify(sm.status) === JSON.stringify(m.status)) {
//Utils.log(m, sm); //Utils.log(m, sm);
m.statusNames = sm.matrix; //m.statusNames = sm.matrix;
} }
}); });
}); });
@ -87,7 +86,7 @@ export const getCommits = async () => {
console.log('getCommits') console.log('getCommits')
try { try {
const commits: ReadCommitResult[] = await plugin.call( const commits: ReadCommitResult[] = await plugin.call(
"dGitProvider", 'dgitApi',
"log", "log",
{ ref: "HEAD" } { ref: "HEAD" }
); );
@ -114,11 +113,7 @@ export const showCurrentBranch = async () => {
const currentcommitoid = await getCommitFromRef("HEAD"); const currentcommitoid = await getCommitFromRef("HEAD");
if (typeof branch === "undefined" || branch.name === "") { if (typeof branch === "undefined" || branch.name === "") {
//toast.warn(`You are in a detached state`);
plugin.call('notification', 'alert', {
type: 'warning',
title: 'You are in a detached state',
})
branch.name = `HEAD detached at ${currentcommitoid}`; branch.name = `HEAD detached at ${currentcommitoid}`;
//canCommit = false; //canCommit = false;
dispatch(setCanCommit(false)); dispatch(setCanCommit(false));
@ -136,7 +131,7 @@ export const currentBranch = async () => {
// eslint-disable-next-line no-useless-catch // eslint-disable-next-line no-useless-catch
try { try {
const branch: branch = const branch: branch =
(await plugin.call("dGitProvider", "currentbranch")) || { (await plugin.call('dgitApi', "currentbranch")) || {
name: "", name: "",
remote: { remote: {
name: "", name: "",
@ -152,14 +147,14 @@ export const currentBranch = async () => {
export const createBranch = async (name: string = "") => { export const createBranch = async (name: string = "") => {
dispatch(setLoading(true)) dispatch(setLoading(true))
if (name) { if (name) {
await plugin.call("dGitProvider", "branch", { ref: name }); await plugin.call('dgitApi', 'branch', { ref: name });
await plugin.call("dGitProvider", "checkout", { ref: name }); await plugin.call('dgitApi', 'checkout', { ref: name });
} }
dispatch(setLoading(false)) dispatch(setLoading(false))
} }
export const getCommitFromRef = async (ref: string) => { export const getCommitFromRef = async (ref: string) => {
const commitOid = await plugin.call("dGitProvider", "resolveref", { const commitOid = await plugin.call('dgitApi', "resolveref", {
ref: ref, ref: ref,
}); });
return commitOid; return commitOid;
@ -169,7 +164,7 @@ const settingsWarning = async () => {
const username = await plugin.call('config' as any, 'getAppParameter', 'settings/github-user-name') const username = await plugin.call('config' as any, 'getAppParameter', 'settings/github-user-name')
const email = await plugin.call('config' as any, 'getAppParameter', 'settings/github-email') const email = await plugin.call('config' as any, 'getAppParameter', 'settings/github-email')
if (!username || !email) { if (!username || !email) {
plugin.call('notification', 'toast', 'Please set your github username and email in the settings') plugin.call('notification' as any, 'toast', 'Please set your github username and email in the settings')
return false; return false;
} else { } else {
return { return {
@ -188,7 +183,7 @@ export const commit = async (message: string = "") => {
return return
} }
const sha = await plugin.call("dGitProvider", "commit", { const sha = await plugin.call('dgitApi', 'commit', {
author: { author: {
name: credentials.username, name: credentials.username,
email: credentials.email, email: credentials.email,
@ -197,12 +192,12 @@ export const commit = async (message: string = "") => {
}); });
sendToGitLog({ sendToGitLog({
type:'success', type: 'success',
message: `Commited: ${sha}` message: `Commited: ${sha}`
}) })
} catch (err) { } catch (err) {
plugin.call('notification', 'toast', `${err}`) plugin.call('notification' as any, 'toast', `${err}`)
} }
} }
@ -212,47 +207,29 @@ export const addall = async (files: fileStatusResult[]) => {
console.log('addall', files.map(f => removeSlash(f.filename))) console.log('addall', files.map(f => removeSlash(f.filename)))
const filesToAdd = files.map(f => removeSlash(f.filename)) const filesToAdd = files.map(f => removeSlash(f.filename))
try { try {
await plugin.call("dGitProvider", "add", { add({ filepath: filesToAdd })
filepath: filesToAdd,
});
} catch (e) { } } catch (e) { }
sendToGitLog({ sendToGitLog({
type:'success', type: 'success',
message: `Added all files to git` message: `Added all files to git`
}) })
} catch (e) { } catch (e) {
plugin.call('notification', 'toast', `${e}`) plugin.call('notification' as any, 'toast', `${e}`)
} }
} }
export const add = async (args: string | undefined) => { export const add = async (filepath: addInput) => {
if (args !== undefined) {
let filename = args; // $(args[0].currentTarget).data('file')
let stagingfiles;
if (filename !== "/") {
filename = removeSlash(filename);
stagingfiles = [filename];
} else {
//await addall();
return;
}
try {
for (const filepath of stagingfiles) {
try { try {
await plugin.call("dGitProvider", "add", { await plugin.call('dgitApi', 'add', filepath);
filepath: removeSlash(filepath),
});
} catch (e) { }
}
sendToGitLog({ sendToGitLog({
type:'success', type: 'success',
message: `Added ${filename} to git` message: `Added to git`
}) })
} catch (e) { } catch (e) {
plugin.call('notification', 'toast', `${e}`) plugin.call('notification' as any, 'toast', `${e}`)
}
} }
} }
const getLastCommmit = async () => { const getLastCommmit = async () => {
@ -265,14 +242,13 @@ const getLastCommmit = async () => {
} }
} }
export const rm = async (args: any) => { export const rm = async (args: rmInput) => {
const filename = args; await plugin.call('dgitApi', 'rm', {
await plugin.call("dGitProvider", "rm", { filepath: removeSlash(args.filepath),
filepath: removeSlash(filename),
}); });
sendToGitLog({ sendToGitLog({
type:'success', type: 'success',
message: `Removed ${filename} from git` message: `Removed from git`
}) })
} }
@ -280,10 +256,10 @@ export const checkoutfile = async (filename: string) => {
const oid = await getLastCommmit(); const oid = await getLastCommmit();
if (oid) if (oid)
try { try {
const commitOid = await plugin.call("dGitProvider", "resolveref", { const commitOid = await plugin.call('dgitApi', 'resolveref', {
ref: oid, ref: oid,
}); });
const { blob } = await plugin.call("dGitProvider", "readblob", { const { blob } = await plugin.call('dgitApi', 'readblob', {
oid: commitOid, oid: commitOid,
filepath: removeSlash(filename), filepath: removeSlash(filename),
}); });
@ -298,47 +274,44 @@ export const checkoutfile = async (filename: string) => {
); );
await enableCallBacks(); await enableCallBacks();
} catch (e) { } catch (e) {
plugin.call('notification', 'toast', `No such file`) plugin.call('notification' as any, 'toast', `No such file`)
} }
} }
export const checkout = async (cmd: any) => { export const checkout = async (cmd: checkoutInput) => {
console.log(cmd) console.log(cmd)
await disableCallBacks(); await disableCallBacks();
await plugin.call('fileManager', 'closeAllFiles') await plugin.call('fileManager', 'closeAllFiles')
try { try {
await plugin.call("dGitProvider", "checkout", cmd); await plugin.call('dgitApi', 'checkout', cmd)
gitlog(); gitlog();
} catch (e) { } catch (e) {
plugin.call('notification', 'toast', `${e}`) plugin.call('notification' as any, 'toast', `${e}`)
} }
await enableCallBacks(); await enableCallBacks();
} }
export const clone = async (url: string, branch: string, depth: number, singleBranch: boolean) => { export const clone = async (input: cloneInputType) => {
console.log(url, branch, depth, singleBranch)
dispatch(setLoading(true)) dispatch(setLoading(true))
try { try {
await disableCallBacks() await disableCallBacks()
// get last part of url // get last part of url
const urlParts = url.split("/"); const urlParts = input.url.split("/");
const lastPart = urlParts[urlParts.length - 1]; const lastPart = urlParts[urlParts.length - 1];
const repoName = lastPart.split(".")[0]; const repoName = lastPart.split(".")[0];
// add timestamp to repo name // add timestamp to repo name
const timestamp = new Date().getTime(); const timestamp = new Date().getTime();
const repoNameWithTimestamp = `${repoName}-${timestamp}`; const repoNameWithTimestamp = `${repoName}-${timestamp}`;
//const token = await tokenWarning(); //const token = await tokenWarning();
const token = await plugin.call('config' as any, 'getAppParameter', 'settings/gist-access-token') const token = await plugin.call('config' as any, 'getAppParameter' as any, 'settings/gist-access-token')
//if (!token) {
// dispatch(setLoading(false)) await plugin.call('dgitApi', 'clone', { ...input, workspaceName: repoNameWithTimestamp });
// return
//} else {
await plugin.call('dGitProvider' as any, 'clone', { url, branch, token, depth, singleBranch }, repoNameWithTimestamp);
await enableCallBacks() await enableCallBacks()
sendToGitLog({ sendToGitLog({
type:'success', type: 'success',
message: `Cloned ${url} to ${repoNameWithTimestamp}` message: `Cloned ${input.url} to ${repoNameWithTimestamp}`
}) })
//} //}
} catch (e: any) { } catch (e: any) {
@ -347,12 +320,12 @@ export const clone = async (url: string, branch: string, depth: number, singleBr
dispatch(setLoading(false)) dispatch(setLoading(false))
} }
export const fetch = async (remote?: string, ref?: string, remoteRef?: string, depth?: number, singleBranch?: boolean, relative?: boolean, quiet?: boolean) => { export const fetch = async (input: fetchInputType) => {
dispatch(setLoading(true)) dispatch(setLoading(true))
await disableCallBacks() await disableCallBacks()
try { try {
await plugin.call('dGitProvider' as any, 'fetch', { remote, ref, remoteRef, depth, singleBranch, relative }); await plugin.call('dgitApi', 'fetch', input);
if (!quiet) { if (!input.quiet) {
await gitlog() await gitlog()
await getBranches() await getBranches()
} }
@ -364,11 +337,11 @@ export const fetch = async (remote?: string, ref?: string, remoteRef?: string, d
await enableCallBacks() await enableCallBacks()
} }
export const pull = async (remote?: string, ref?: string, remoteRef?: string) => { export const pull = async (input: pullInputType) => {
dispatch(setLoading(true)) dispatch(setLoading(true))
await disableCallBacks() await disableCallBacks()
try { try {
await plugin.call('dGitProvider' as any, 'pull', { remote, ref, remoteRef }) await plugin.call('dgitApi', 'pull', input)
await gitlog() await gitlog()
} catch (e: any) { } catch (e: any) {
await parseError(e) await parseError(e)
@ -377,11 +350,11 @@ export const pull = async (remote?: string, ref?: string, remoteRef?: string) =>
await enableCallBacks() await enableCallBacks()
} }
export const push = async (remote?: string, ref?: string, remoteRef?: string, force?: boolean) => { export const push = async (input: pushInputType) => {
dispatch(setLoading(true)) dispatch(setLoading(true))
await disableCallBacks() await disableCallBacks()
try { try {
await plugin.call('dGitProvider' as any, 'push', { remote, ref, remoteRef, force }) await plugin.call('dgitApi', 'push', input)
} catch (e: any) { } catch (e: any) {
await parseError(e) await parseError(e)
} }
@ -390,7 +363,7 @@ export const push = async (remote?: string, ref?: string, remoteRef?: string, fo
} }
const tokenWarning = async () => { const tokenWarning = async () => {
const token = await plugin.call('config' as any, 'getAppParameter', 'settings/gist-access-token') const token = await plugin.call('config' as any, 'getAppParameter' as any, 'settings/gist-access-token')
if (!token) { if (!token) {
return false; return false;
} else { } else {
@ -402,7 +375,7 @@ const parseError = async (e: any) => {
console.trace(e) console.trace(e)
// if message conttains 401 Unauthorized, show token warning // if message conttains 401 Unauthorized, show token warning
if (e.message.includes('401')) { if (e.message.includes('401')) {
const result = await plugin.call('notification', 'modal', { const result = await plugin.call('notification' as any, 'modal' as any, {
title: 'The GitHub token may be missing or invalid', title: 'The GitHub token may be missing or invalid',
message: 'Please check the GitHub token and try again. Error: 401 Unauthorized', message: 'Please check the GitHub token and try again. Error: 401 Unauthorized',
okLabel: 'Go to settings', okLabel: 'Go to settings',
@ -413,7 +386,7 @@ const parseError = async (e: any) => {
} }
// if message contains 404 Not Found, show repo not found // if message contains 404 Not Found, show repo not found
else if (e.message.includes('404')) { else if (e.message.includes('404')) {
await plugin.call('notification', 'modal', { await plugin.call('notification' as any, 'modal' as any, {
title: 'Repository not found', title: 'Repository not found',
message: 'Please check the URL and try again.', message: 'Please check the URL and try again.',
okLabel: 'Go to settings', okLabel: 'Go to settings',
@ -423,7 +396,7 @@ const parseError = async (e: any) => {
} }
// if message contains 403 Forbidden // if message contains 403 Forbidden
else if (e.message.includes('403')) { else if (e.message.includes('403')) {
await plugin.call('notification', 'modal', { await plugin.call('notification' as any, 'modal' as any, {
title: 'The GitHub token may be missing or invalid', title: 'The GitHub token may be missing or invalid',
message: 'Please check the GitHub token and try again. Error: 403 Forbidden', message: 'Please check the GitHub token and try again. Error: 403 Forbidden',
okLabel: 'Go to settings', okLabel: 'Go to settings',
@ -431,14 +404,14 @@ const parseError = async (e: any) => {
type: ModalTypes.confirm type: ModalTypes.confirm
}) })
} else if (e.toString().includes('NotFoundError') && !e.toString().includes('fetch')) { } else if (e.toString().includes('NotFoundError') && !e.toString().includes('fetch')) {
await plugin.call('notification', 'modal', { await plugin.call('notification' as any, 'modal', {
title: 'Remote branch not found', title: 'Remote branch not found',
message: 'The branch you are trying to fetch does not exist on the remote. If you have forked this branch from another branch, you may need to fetch the original branch first or publish this branch on the remote.', message: 'The branch you are trying to fetch does not exist on the remote. If you have forked this branch from another branch, you may need to fetch the original branch first or publish this branch on the remote.',
okLabel: 'OK', okLabel: 'OK',
type: ModalTypes.alert type: ModalTypes.alert
}) })
} else { } else {
await plugin.call('notification', 'alert', { await plugin.call('notification' as any, 'alert' as any, {
title: 'Error', title: 'Error',
message: e.message message: e.message
}) })
@ -449,13 +422,13 @@ export const repositories = async () => {
try { try {
const token = await tokenWarning(); const token = await tokenWarning();
if (token) { if (token) {
let repos = await plugin.call('dGitProvider' as any, 'repositories', { token, per_page: 100 }) let repos = await plugin.call('dgitApi', 'repositories', { token, per_page: 100 })
dispatch(setRepos(repos)) dispatch(setRepos(repos))
let page = 2 let page = 2
let hasMoreData = true let hasMoreData = true
const per_page = 100 const per_page = 100
while (hasMoreData) { while (hasMoreData) {
const pagedResponse = await plugin.call('dGitProvider' as any, 'repositories', { token, page: page, per_page: per_page }) const pagedResponse = await plugin.call('dgitApi', 'repositories', { token, page: page, per_page: per_page })
if (pagedResponse.length < per_page) { if (pagedResponse.length < per_page) {
hasMoreData = false hasMoreData = false
} }
@ -465,7 +438,7 @@ export const repositories = async () => {
} }
} else { } else {
plugin.call('notification', 'alert', { plugin.call('notification' as any, 'alert', {
title: 'Error getting repositories', title: 'Error getting repositories',
message: `Please check your GitHub token in the GitHub settings... cannot connect to GitHub` message: `Please check your GitHub token in the GitHub settings... cannot connect to GitHub`
}) })
@ -473,7 +446,7 @@ export const repositories = async () => {
} }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
plugin.call('notification', 'alert', { plugin.call('notification' as any, 'alert', {
title: 'Error getting repositories', title: 'Error getting repositories',
message: `${e.message}: Please check your GitHub token in the GitHub settings.` message: `${e.message}: Please check your GitHub token in the GitHub settings.`
}) })
@ -485,13 +458,13 @@ export const remoteBranches = async (owner: string, repo: string) => {
try { try {
const token = await tokenWarning(); const token = await tokenWarning();
if (token) { if (token) {
let branches = await plugin.call('dGitProvider' as any, 'remotebranches', { token, owner, repo, per_page: 100 }); let branches = await plugin.call('dgitApi' as any, 'remotebranches', { token, owner, repo, per_page: 100 });
dispatch(setRemoteBranches(branches)) dispatch(setRemoteBranches(branches))
let page = 2 let page = 2
let hasMoreData = true let hasMoreData = true
const per_page = 100 const per_page = 100
while (hasMoreData) { while (hasMoreData) {
const pagedResponse = await plugin.call('dGitProvider' as any, 'remotebranches', { token, owner, repo, page: page, per_page: per_page }) const pagedResponse = await plugin.call('dgitApi' as any, 'remotebranches', { token, owner, repo, page: page, per_page: per_page })
if (pagedResponse.length < per_page) { if (pagedResponse.length < per_page) {
hasMoreData = false hasMoreData = false
} }
@ -500,7 +473,7 @@ export const remoteBranches = async (owner: string, repo: string) => {
page++ page++
} }
} else { } else {
plugin.call('notification', 'alert', { plugin.call('notification' as any, 'alert', {
title: 'Error getting branches', title: 'Error getting branches',
message: `Please check your GitHub token in the GitHub settings. It needs to have access to the branches.` message: `Please check your GitHub token in the GitHub settings. It needs to have access to the branches.`
}) })
@ -508,7 +481,7 @@ export const remoteBranches = async (owner: string, repo: string) => {
} }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
plugin.call('notification', 'alert', { plugin.call('notification' as any, 'alert', {
title: 'Error', title: 'Error',
message: e.message message: e.message
}) })
@ -532,7 +505,7 @@ export const remoteCommits = async (url: string, branch: string, length: number)
const token = await tokenWarning(); const token = await tokenWarning();
if (token) { if (token) {
console.log(token, owner, repo, branch, length) console.log(token, owner, repo, branch, length)
const commits = await plugin.call('dGitProvider' as any, 'remotecommits', { token, owner, repo, branch, length }); const commits = await plugin.call('dgitApi' as any, 'remotecommits', { token, owner, repo, branch, length });
console.log(commits, 'remote commits') console.log(commits, 'remote commits')
} else { } else {
sendToGitLog({ sendToGitLog({
@ -542,7 +515,7 @@ export const remoteCommits = async (url: string, branch: string, length: number)
} }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
plugin.call('notification', 'alert', { plugin.call('notification' as any, 'alert', {
title: 'Error', title: 'Error',
message: e.message message: e.message
}) })
@ -551,9 +524,9 @@ export const remoteCommits = async (url: string, branch: string, length: number)
export const saveGitHubCredentials = async (credentials: { username: string, email: string, token: string }) => { export const saveGitHubCredentials = async (credentials: { username: string, email: string, token: string }) => {
try { try {
await plugin.call('config' as any, 'setAppParameter', 'settings/github-user-name', credentials.username) await plugin.call('config' as any, 'setAppParameter' as any, 'settings/github-user-name', credentials.username)
await plugin.call('config' as any, 'setAppParameter', 'settings/github-email', credentials.email) await plugin.call('config' as any, 'setAppParameter' as any, 'settings/github-email', credentials.email)
await plugin.call('config' as any, 'setAppParameter', 'settings/gist-access-token', credentials.token) await plugin.call('config' as any, 'setAppParameter' as any, 'settings/gist-access-token', credentials.token)
} catch (e) { } catch (e) {
console.log(e) console.log(e)
} }
@ -562,9 +535,9 @@ export const saveGitHubCredentials = async (credentials: { username: string, ema
export const getGitHubCredentials = async () => { export const getGitHubCredentials = async () => {
if (!plugin) return if (!plugin) return
try { try {
const username = await plugin.call('config' as any, 'getAppParameter', 'settings/github-user-name') const username = await plugin.call('config' as any, 'getAppParameter' as any, 'settings/github-user-name')
const email = await plugin.call('config' as any, 'getAppParameter', 'settings/github-email') const email = await plugin.call('config' as any, 'getAppParameter' as any, 'settings/github-email')
const token = await plugin.call('config' as any, 'getAppParameter', 'settings/gist-access-token') const token = await plugin.call('config' as any, 'getAppParameter' as any, 'settings/gist-access-token')
return { return {
username, username,
email, email,
@ -584,7 +557,7 @@ export const getGitHubUser = async () => {
user: GitHubUser, user: GitHubUser,
ratelimit: RateLimit ratelimit: RateLimit
scopes: string[] scopes: string[]
} = await plugin.call('dGitProvider' as any, 'getGitHubUser', { token }); } = await plugin.call('dgitApi' as any, 'getGitHubUser', { token });
console.log('GET USER"', data) console.log('GET USER"', data)
@ -600,7 +573,7 @@ export const getGitHubUser = async () => {
} }
export const statusMatrix = async (filepaths: string[]) => { export const statusMatrix = async (filepaths: string[]) => {
const matrix = await plugin.call("dGitProvider", "status", { ref: "HEAD", filepaths: filepaths || ['.']}); const matrix = await plugin.call('dgitApi', 'status', { ref: "HEAD", filepaths: filepaths || ['.'] });
const result = (matrix || []).map((x) => { const result = (matrix || []).map((x) => {
return { return {
filename: `/${x.shift()}`, filename: `/${x.shift()}`,
@ -616,7 +589,7 @@ export const diffFiles = async (filename: string | undefined) => {
} }
export const resolveRef = async (ref: string) => { export const resolveRef = async (ref: string) => {
const oid = await plugin.call("dGitProvider", "resolveref", { const oid = await plugin.call('dgitApi', "resolveref", {
ref, ref,
}); });
return oid; return oid;
@ -636,7 +609,7 @@ export const diff = async (commitChange: commitChange) => {
} else { } else {
try { try {
const modifiedContentReadBlobResult: ReadBlobResult = await plugin.call("dGitProvider", "readblob", { const modifiedContentReadBlobResult: ReadBlobResult = await plugin.call('dgitApi', "readblob", {
oid: commitChange.hashModified, oid: commitChange.hashModified,
filepath: removeSlash(commitChange.path), filepath: removeSlash(commitChange.path),
}); });
@ -651,7 +624,7 @@ export const diff = async (commitChange: commitChange) => {
} }
try { try {
const originalContentReadBlobResult: ReadBlobResult = await plugin.call("dGitProvider", "readblob", { const originalContentReadBlobResult: ReadBlobResult = await plugin.call('dgitApi', "readblob", {
oid: commitChange.hashOriginal, oid: commitChange.hashOriginal,
filepath: removeSlash(commitChange.path), filepath: removeSlash(commitChange.path),
}); });
@ -672,7 +645,7 @@ export const getCommitChanges = async (oid1: string, oid2: string, branch?: bran
let log let log
try { try {
// check if oid2 exists // check if oid2 exists
log = await plugin.call('dGitProvider', 'log', { log = await plugin.call('dgitApi', 'log', {
ref: branch ? branch.name : 'HEAD', ref: branch ? branch.name : 'HEAD',
}) })
console.log(log, 'log') console.log(log, 'log')
@ -683,10 +656,19 @@ export const getCommitChanges = async (oid1: string, oid2: string, branch?: bran
const foundCommit = log.find((commit: ReadCommitResult) => commit.oid === oid2) const foundCommit = log.find((commit: ReadCommitResult) => commit.oid === oid2)
if (!foundCommit && remote) { if (!foundCommit && remote) {
console.log('getCommitChanges fetching remote') console.log('getCommitChanges fetching remote')
await fetch(remote ? remote.name : null, branch ? branch.name : null, null, 5, true, true) //await fetch(remote ? remote.name : null, branch ? branch.name : null, null, 5, true, true)
await fetch({
remote: remote,
singleBranch: true,
quiet: true,
relative: true,
depth: 5,
ref: branch,
remoteRef: null
})
} }
} }
const result: commitChange[] = await plugin.call('dGitProvider', 'getCommitChanges', oid1, oid2) const result: commitChange[] = await plugin.call('dgitApi', 'getCommitChanges', oid1, oid2)
dispatch(setCommitChanges(result)) dispatch(setCommitChanges(result))
return result return result
} catch (e) { } catch (e) {
@ -714,27 +696,27 @@ export const fetchBranch = async (branch: branch, page: number) => {
dispatch(resetRemoteBranchCommits({ branch })) dispatch(resetRemoteBranchCommits({ branch }))
} }
const { owner, repo } = await getRepoDetails(branch.remote.url); const { owner, repo } = await getRepoDetails(branch.remote.url);
const rc = await plugin.call('dGitProvider' as any, 'remotecommits', { token, owner: owner, repo: repo, branch: branch.name, length, page }); const rc = await plugin.call('dgitApi', 'remotecommits', { token, owner: owner, repo: repo, branch: branch.name, length, page });
console.log(rc, 'remote commits from octokit') console.log(rc, 'remote commits from octokit')
dispatch(setRemoteBranchCommits({ branch, commits: rc })) dispatch(setRemoteBranchCommits({ branch, commits: rc }))
return return
} }
export const getBranchDifferences = async (branch: branch, remote: remote, state: gitState) => { export const getBranchDifferences = async (branch: branch, remote: remote, state: gitState) => {
if (!remote && state){ if (!remote && state) {
if (state.defaultRemote){ if (state.defaultRemote) {
remote = state.defaultRemote remote = state.defaultRemote
} else { } else {
remote = state.remotes.find((remote: remote) => remote.name === 'origin') remote = state.remotes.find((remote: remote) => remote.name === 'origin')
} }
if (!remote && state.remotes[0]){ if (!remote && state.remotes[0]) {
remote = state.remotes[0] remote = state.remotes[0]
} }
} }
if (!remote) return if (!remote) return
try { try {
console.log('compare', branch, remote) console.log('compare', branch, remote)
const branchDifference: branchDifference = await plugin.call('dGitProvider', 'compareBranches', { const branchDifference: branchDifference = await plugin.call('dgitApi', 'compareBranches', {
branch, branch,
remote remote
}) })
@ -756,7 +738,7 @@ export const getBranchCommits = async (branch: branch, page: number) => {
try { try {
console.log(branch) console.log(branch)
if (!branch.remote) { if (!branch.remote) {
const commits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', { const commits: ReadCommitResult[] = await plugin.call('dgitApi', 'log', {
ref: branch.name, ref: branch.name,
}) })
console.log(commits) console.log(commits)
@ -778,7 +760,7 @@ export const setDefaultRemote = async (remote: remote) => {
export const addRemote = async (remote: remote) => { export const addRemote = async (remote: remote) => {
try { try {
await plugin.call('dGitProvider', 'addremote', remote) await plugin.call('dgitApi', 'addremote', remote)
await getRemotes() await getRemotes()
} catch (e) { } catch (e) {
console.log(e) console.log(e)
@ -787,7 +769,7 @@ export const addRemote = async (remote: remote) => {
export const removeRemote = async (remote: remote) => { export const removeRemote = async (remote: remote) => {
try { try {
await plugin.call('dGitProvider', 'delremote', remote) await plugin.call('dgitApi', 'delremote', remote)
await getRemotes() await getRemotes()
} catch (e) { } catch (e) {
console.log(e) console.log(e)

@ -2,10 +2,12 @@
import { ViewPlugin } from "@remixproject/engine-web"; import { ViewPlugin } from "@remixproject/engine-web";
import React from "react"; import React from "react";
import { setCanUseApp, setLoading, setRepoName, setGItHubToken, setLog } from "../state/gitpayload"; import { setCanUseApp, setLoading, setRepoName, setGItHubToken, setLog } from "../state/gitpayload";
import { gitActionDispatch } from "../types"; import { CustomRemixApi, customDGitSystem, gitActionDispatch } from "../types";
import { Plugin } from "@remixproject/engine";
import { diffFiles, getBranches, getFileStatusMatrix, getGitHubUser, getRemotes, gitlog, setPlugin } from "./gitactions"; import { diffFiles, getBranches, getFileStatusMatrix, getGitHubUser, getRemotes, gitlog, setPlugin } from "./gitactions";
import { Profile } from "@remixproject/plugin-utils";
let plugin: ViewPlugin, gitDispatch: React.Dispatch<gitActionDispatch>, loaderDispatch: React.Dispatch<any>, loadFileQueue: AsyncDebouncedQueue let plugin: Plugin<any, CustomRemixApi>, gitDispatch: React.Dispatch<gitActionDispatch>, loaderDispatch: React.Dispatch<any>, loadFileQueue: AsyncDebouncedQueue
let callBackEnabled: boolean = false let callBackEnabled: boolean = false
let syncTimer: NodeJS.Timer = null let syncTimer: NodeJS.Timer = null
@ -34,7 +36,7 @@ class AsyncDebouncedQueue {
export const setCallBacks = (viewPlugin: ViewPlugin, gitDispatcher: React.Dispatch<gitActionDispatch>, loaderDispatcher: React.Dispatch<any>) => { export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch<gitActionDispatch>, loaderDispatcher: React.Dispatch<any>) => {
plugin = viewPlugin plugin = viewPlugin
gitDispatch = gitDispatcher gitDispatch = gitDispatcher
loaderDispatch = loaderDispatcher loaderDispatch = loaderDispatcher
@ -49,10 +51,10 @@ export const setCallBacks = (viewPlugin: ViewPlugin, gitDispatcher: React.Dispat
}) })
}); });
plugin.on('dGitProvider', 'checkout' as any, async () => { plugin.on('dgitApi', 'checkout', async () => {
//await synTimerStart(); //await synTimerStart();
}) })
plugin.on('dGitProvider', 'branch' as any, async () => { plugin.on('dgitApi', 'branch', async () => {
//await synTimerStart(); //await synTimerStart();
}) })
@ -98,23 +100,23 @@ export const setCallBacks = (viewPlugin: ViewPlugin, gitDispatcher: React.Dispat
//await synTimerStart(); //await synTimerStart();
}); });
plugin.on('dGitProvider', 'checkout', async () => { plugin.on('dgitApi', 'checkout', async () => {
}) })
plugin.on('dGitProvider', 'init', async () => { plugin.on('dgitApi', 'init', async () => {
}) })
plugin.on('dGitProvider', 'add', async () => { plugin.on('dgitApi', 'add', async () => {
loadFileQueue.enqueue(async () => { loadFileQueue.enqueue(async () => {
loadFiles() loadFiles()
}, 10) }, 10)
}) })
plugin.on('dGitProvider', 'rm', async () => { plugin.on('dgitApi', 'rm', async () => {
loadFileQueue.enqueue(async () => { loadFileQueue.enqueue(async () => {
loadFiles() loadFiles()
}, 10) }, 10)
}) })
plugin.on('dGitProvider', 'commit', async () => { plugin.on('dgitApi', 'commit', async () => {
loadFileQueue.enqueue(async () => { loadFileQueue.enqueue(async () => {
gitlog() gitlog()
}, 10) }, 10)
@ -123,13 +125,13 @@ export const setCallBacks = (viewPlugin: ViewPlugin, gitDispatcher: React.Dispat
type: 'success' type: 'success'
})) }))
}) })
plugin.on('dGitProvider', 'branch', async () => { plugin.on('dgitApi', 'branch', async () => {
gitDispatch(setLog({ gitDispatch(setLog({
message: "Created Branch", message: "Created Branch",
type: "success" type: "success"
})) }))
}) })
plugin.on('dGitProvider', 'clone', async () => { plugin.on('dgitApi', 'clone', async () => {
gitDispatch(setLog({ gitDispatch(setLog({
message: "Cloned Repository", message: "Cloned Repository",
type: "success" type: "success"
@ -138,17 +140,17 @@ export const setCallBacks = (viewPlugin: ViewPlugin, gitDispatcher: React.Dispat
loadFiles() loadFiles()
}) })
}) })
plugin.on('manager', 'pluginActivated', async (p: Plugin) => { plugin.on('manager', 'pluginActivated', async (p: Profile<any>) => {
if (p.name === 'dGitProvider') { if (p.name === 'dgitApi') {
getGitHubUser(); getGitHubUser();
plugin.off('manager', 'pluginActivated'); plugin.off('manager', 'pluginActivated');
} }
}) })
plugin.on('config', 'configChanged', async () => { plugin.on('config' as any, 'configChanged', async () => {
await getGitConfig() await getGitConfig()
}) })
plugin.on('settings', 'configChanged', async () => { plugin.on('settings' as any, 'configChanged', async () => {
await getGitConfig() await getGitConfig()
}) })
@ -156,9 +158,9 @@ export const setCallBacks = (viewPlugin: ViewPlugin, gitDispatcher: React.Dispat
} }
export const getGitConfig = async () => { export const getGitConfig = async () => {
const username = await plugin.call('settings', 'get', 'settings/github-user-name') const username = await plugin.call('settings' as any, 'get', 'settings/github-user-name')
const email = await plugin.call('settings', 'get', 'settings/github-email') const email = await plugin.call('settings' as any, 'get', 'settings/github-email')
const token = await plugin.call('settings', 'get', 'settings/gist-access-token') const token = await plugin.call('settings' as any, 'get', 'settings/gist-access-token')
const config = { username, email, token } const config = { username, email, token }
gitDispatch(setGItHubToken(config.token)) gitDispatch(setGItHubToken(config.token))
return config return config
@ -206,7 +208,7 @@ const getStorageUsed = async () => {
try { try {
const storageUsed = await plugin.call("storage" as any, "getStorage" as any); const storageUsed = await plugin.call("storage" as any, "getStorage" as any);
} catch (e) { } catch (e) {
const storage: string = await plugin.call("dGitProvider", "localStorageUsed" as any); const storage: string = await plugin.call('dgitApi', "localStorageUsed" as any);
const storageUsed = { const storageUsed = {
usage: parseFloat(storage) * 1000, usage: parseFloat(storage) * 1000,
quota: 10000000, quota: 10000000,

@ -1,20 +1,20 @@
import { ReadCommitResult } from "isomorphic-git" import { ReadCommitResult } from "isomorphic-git"
import React from "react" import React from "react"
import { branch, commitChange, fileStatusResult, gitLog, gitState, remote } from "../types" import { addInput, branch, checkoutInput, cloneInputType, commitChange, fetchInputType, fileStatusResult, gitLog, gitState, pullInputType, pushInputType, remote, rmInput } from "../types"
export interface gitActions { export interface gitActions {
removeRemote(remote: remote): void removeRemote(remote: remote): void
clone(url: string, path: string, depth: number, singleBranch: boolean): Promise<void> clone(input: cloneInputType): Promise<void>
add(path: string): Promise<void> add(input: addInput): Promise<void>
rm(path: string): Promise<void> rm(input: rmInput): Promise<void>
commit(message: string): Promise<any> commit(message: string): Promise<any>
addall(files: fileStatusResult[]): Promise<void> addall(files: fileStatusResult[]): Promise<void>
push(remote?: string, ref?: string, remoteRef?: string, force?: boolean): Promise<void> push(input: pushInputType): Promise<void>
pull(remote?: string, ref?: string, remoteRef?: string): Promise<void> pull(input: pullInputType): Promise<void>
fetch(remote?: string, ref?: string, remoteRef?: string, depth?: number, singleBranch?: boolean, relative?: boolean, quiet?: boolean): Promise<void> fetch(input: fetchInputType): Promise<void>
repositories(): Promise<any> repositories(): Promise<any>
checkoutfile(file: string): Promise<void> checkoutfile(file: string): Promise<void>
checkout(cmd: any): Promise<void> checkout(input: checkoutInput): Promise<void>
createBranch(branch: string): Promise<void> createBranch(branch: string): Promise<void>
remoteBranches(owner: string, repo: string): Promise<any> remoteBranches(owner: string, repo: string): Promise<any>
getCommitChanges(oid1: string, oid2: string, branch?: branch, remote?: remote): Promise<commitChange[] | boolean> getCommitChanges(oid1: string, oid2: string, branch?: branch, remote?: remote): Promise<commitChange[] | boolean>

@ -1,5 +1,5 @@
import { ReadCommitResult } from "isomorphic-git" import { ReadCommitResult } from "isomorphic-git"
import { GitHubUser, branch, commitChange, fileStatusResult, remote, pagedCommits, branchDifference, gitLog } from "../types" import { GitHubUser, branch, commitChange, fileStatusResult, remote, pagedCommits, branchDifference, gitLog, repository } from "../types"
import { Endpoints } from "@octokit/types" import { Endpoints } from "@octokit/types"
export const fileStatus = (files: fileStatusResult[]) => { export const fileStatus = (files: fileStatusResult[]) => {
@ -30,7 +30,7 @@ export const setBranches = (branches: any[]) => {
} }
} }
export const setRepos = (repos: any[]) => { export const setRepos = (repos: repository[]) => {
return { return {
type: 'SET_REPOS', type: 'SET_REPOS',
payload: repos payload: repos

@ -1,8 +1,164 @@
import { Endpoints } from "@octokit/types" import { Endpoints } from "@octokit/types"
import { CommitObject, ReadCommitResult } from "isomorphic-git" import { IRemixApi } from "@remixproject/plugin-api"
import { LibraryProfile, StatusEvents } from "@remixproject/plugin-utils"
import { CommitObject, ReadBlobResult, ReadCommitResult, StatusRow } from "isomorphic-git"
export type GitHubUser = Endpoints["GET /user"]["response"]['data'] export type GitHubUser = Endpoints["GET /user"]["response"]['data']
export type RateLimit = Endpoints["GET /rate_limit"]["response"]["data"] export type RateLimit = Endpoints["GET /rate_limit"]["response"]["data"]
export interface customDGitSystem {
events: {
"checkout": () => void
"clone": () => void
"add": () => void
"rm": () => void
"commit": () => void
"branch": () => void
"init": () => void
} & StatusEvents,
methods: {
getCommitChanges(oid1: string, oid2: string): Promise<commitChange[]>
//getBranchCommits(branch: branch): Promise<ReadCommitResult[]>
//fetchBranch(branch: branch): Promise<any>
//remotebranches(owner: string, repo: string): Promise<branch[]>
//remoteCommits(url: string, branch: string, length: number): Promise<ReadCommitResult[]>
repositories(input: repositoriesInput): Promise<repository[]>
clone(input: cloneInputType): Promise<any>
branches(input?: branchesInput): Promise<branch[]>,
remotes(): Promise<remote[]>,
log(cmd: { ref: string }): Promise<ReadCommitResult[]>,
remotecommits(input: remoteCommitsInputType): Promise<pagedCommits[]>
fetch(input: fetchInputType): Promise<any>
pull(input: pullInputType): Promise<any>
push(input: pushInputType): Promise<any>
//getGitHubUser(token: string): Promise<{ user: GitHubUser, ratelimit: RateLimit }>
//saveGitHubCredentials(credentials: { username: string, email: string, token: string }): Promise<any>
//getGitHubCredentials(): Promise<{ username: string, email: string, token: string }>
currentbranch(input?: currentBranchInput): Promise<branch>
branch(input: branchInputType): Promise<void>
checkout(input: checkoutInput): Promise<void>
add(input: addInput): Promise<void>
rm(input: rmInput): Promise<void>
resolveref(input: resolveRefInput): Promise<string>
readblob(input: readBlobInput): Promise<ReadBlobResult>
commit(input: commitInput): Promise<string>
addremote(input: remote): Promise<void>
delremote(input: remote): Promise<void>
status(input?: statusInput): Promise<Array<StatusRow>>
compareBranches(input: compareBranchesInput): Promise<branchDifference>
init(input?: initInput): Promise<void>
updateSubmodules: (input: updateSubmodulesInput) => Promise<void>
}
}
export interface ICustomRemixApi extends IRemixApi {
dgitApi: customDGitSystem
}
export declare type CustomRemixApi = Readonly<ICustomRemixApi>;
export type initInput = {
defaultBranch: string
}
export type updateSubmodulesInput = {
dir?: string
token?: string
}
export type remoteCommitsInputType = {
owner: string, repo: string, token: string, branch: string, length: number, page: number
}
export type compareBranchesInput = {
branch: branch, remote: remote
}
export type fetchInputType = {
remote: remote, ref: branch, remoteRef?: branch, depth: number, singleBranch: boolean, relative: boolean, quiet?: boolean
}
export type pullInputType = {
remote: remote, ref: branch, remoteRef?: branch
}
export type pushInputType = {
remote: remote, ref: branch, remoteRef?: branch, force?: boolean
}
export type branchInputType = {
ref: string,
checkout?: boolean
refresh?: boolean
}
export type currentBranchInput = {
fs: any,
dir: string
}
export type checkoutInput = {
ref: string,
force?: boolean,
remote?: string
refresh?: boolean
}
export type addInput = {
filepath: string | string[]
}
export type rmInput = {
filepath: string
}
export type resolveRefInput = {
ref: string
}
export type readBlobInput = {
oid: string,
filepath: string
}
export type commitInput = {
author: {
name: string,
email: string,
},
message: string,
}
export type branchesInput = {
fs?: any
dir?: string
}
export interface cloneInputType {
url: string,
branch?: string,
depth?: number,
singleBranch?: boolean
workspaceName?: string
workspaceExists?: boolean
token?: string
}
export interface repositoriesInput { token: string, page?: number, per_page?: number }
export interface statusInput { ref: string, filepaths?: string[] }
export const dGitProfile: LibraryProfile<customDGitSystem> = {
name: 'dgitApi',
methods: ['clone', 'branches', 'remotes', 'getCommitChanges', 'log', 'remotecommits'],
}
export interface customGitApi extends IRemixApi {
dgit: customDGitSystem
}
export type gitState = { export type gitState = {
currentBranch: branch currentBranch: branch
commits: ReadCommitResult[] commits: ReadCommitResult[]
@ -38,7 +194,7 @@ export type gitState = {
log: gitLog[] log: gitLog[]
} }
export type gitLog = { export type gitLog = {
type: 'error' | 'warning' | 'info' |'success', type: 'error' | 'warning' | 'info' | 'success',
message: string message: string
} }

@ -71,7 +71,7 @@ function HomeTabGetStarted({ plugin }: HomeTabGetStartedProps) {
const metadata = TEMPLATE_METADATA[templateName] const metadata = TEMPLATE_METADATA[templateName]
if (metadata) { if (metadata) {
if (metadata.type === 'git') { if (metadata.type === 'git') {
await plugin.call('dGitProvider', 'clone', { url: metadata.url, branch: metadata.branch }, templateDisplayName) await plugin.call('dgitApi', 'clone', { url: metadata.url, branch: metadata.branch }, templateDisplayName)
} else if (metadata && metadata.type === 'plugin') { } else if (metadata && metadata.type === 'plugin') {
await plugin.appManager.activatePlugin('filePanel') await plugin.appManager.activatePlugin('filePanel')
templateDisplayName = await plugin.call('filePanel', 'getAvailableWorkspaceName', templateDisplayName) templateDisplayName = await plugin.call('filePanel', 'getAvailableWorkspaceName', templateDisplayName)

@ -1,4 +1,5 @@
import { fileDecoration } from '@remix-ui/file-decorators' import { fileDecoration } from '@remix-ui/file-decorators'
import { branch } from '@remix-ui/git';
import { Action, ActionPayloadTypes, FileTree, WorkspaceElement, action } from '../types' import { Action, ActionPayloadTypes, FileTree, WorkspaceElement, action } from '../types'
export const setCurrentWorkspace = (workspace: { name: string; isGitRepo: boolean; }): Action<'SET_CURRENT_WORKSPACE'> => { export const setCurrentWorkspace = (workspace: { name: string; isGitRepo: boolean; }): Action<'SET_CURRENT_WORKSPACE'> => {
@ -280,7 +281,7 @@ export const setCurrentWorkspaceBranches = (branches?: { remote: any, name: stri
} }
} }
export const setCurrentWorkspaceCurrentBranch = (currentBranch?: string): Action<'SET_CURRENT_WORKSPACE_CURRENT_BRANCH'> => { export const setCurrentWorkspaceCurrentBranch = (currentBranch?: branch): Action<'SET_CURRENT_WORKSPACE_CURRENT_BRANCH'> => {
return { return {
type: 'SET_CURRENT_WORKSPACE_CURRENT_BRANCH', type: 'SET_CURRENT_WORKSPACE_CURRENT_BRANCH',
payload: currentBranch payload: currentBranch

@ -42,8 +42,9 @@ import { ROOT_PATH, slitherYml, solTestYml, tsSolTestYml } from '../utils/consta
import { IndexedDBStorage } from '../../../../../../apps/remix-ide/src/app/files/filesystems/indexedDB' import { IndexedDBStorage } from '../../../../../../apps/remix-ide/src/app/files/filesystems/indexedDB'
import { getUncommittedFiles } from '../utils/gitStatusFilter' import { getUncommittedFiles } from '../utils/gitStatusFilter'
import { AppModal, ModalTypes } from '@remix-ui/app' import { AppModal, ModalTypes } from '@remix-ui/app'
import { branch } from '@remix-ui/git' import { CustomRemixApi, branch, cloneInputType, customDGitSystem } from '@remix-ui/git'
import * as templates from '@remix-project/remix-ws-templates' import * as templates from '@remix-project/remix-ws-templates'
import { Plugin } from "@remixproject/engine";
declare global { declare global {
interface Window { interface Window {
@ -56,27 +57,28 @@ const NO_WORKSPACE = ' - none - '
const ELECTRON = 'electron' const ELECTRON = 'electron'
const queryParams = new QueryParams() const queryParams = new QueryParams()
const _paq = (window._paq = window._paq || []) //eslint-disable-line const _paq = (window._paq = window._paq || []) //eslint-disable-line
let plugin, dispatch: React.Dispatch<any> let plugin: any, dgitPlugin: Plugin<any, CustomRemixApi>,dispatch: React.Dispatch<any>
export const setPlugin = (filePanelPlugin, reducerDispatch) => { export const setPlugin = (filePanelPlugin, reducerDispatch) => {
plugin = filePanelPlugin plugin = filePanelPlugin
dgitPlugin = filePanelPlugin
dispatch = reducerDispatch dispatch = reducerDispatch
plugin.on('dGitProvider', 'checkout', async () => { dgitPlugin.on('dgitApi', 'checkout', async () => {
await checkGit() await checkGit()
}) })
plugin.on('dGitProvider', 'init', async () => { dgitPlugin.on('dgitApi', 'init', async () => {
await checkGit() await checkGit()
}) })
plugin.on('dGitProvider', 'add', async () => { dgitPlugin.on('dgitApi', 'add', async () => {
await checkGit() await checkGit()
}) })
plugin.on('dGitProvider', 'commit', async () => { dgitPlugin.on('dgitApi', 'commit', async () => {
await checkGit() await checkGit()
}) })
plugin.on('dGitProvider', 'branch', async () => { dgitPlugin.on('dgitApi', 'branch', async () => {
await checkGit() await checkGit()
}) })
plugin.on('dGitProvider', 'clone', async () => { dgitPlugin.on('dgitApi', 'clone', async () => {
await checkGit() await checkGit()
}) })
plugin.on('config', 'configChanged', async () => { plugin.on('config', 'configChanged', async () => {
@ -153,7 +155,7 @@ export const createWorkspace = async (
if (isGitRepo && createCommit) { if (isGitRepo && createCommit) {
const name = await plugin.call('settings', 'get', 'settings/github-user-name') const name = await plugin.call('settings', 'get', 'settings/github-user-name')
const email = await plugin.call('settings', 'get', 'settings/github-email') const email = await plugin.call('settings', 'get', 'settings/github-email')
const currentBranch: branch = await plugin.call('dGitProvider', 'currentbranch') const currentBranch: branch = await dgitPlugin.call('dgitApi', 'currentbranch')
if (!currentBranch) { if (!currentBranch) {
if (!name || !email) { if (!name || !email) {
@ -162,22 +164,22 @@ export const createWorkspace = async (
// commit the template as first commit // commit the template as first commit
plugin.call('notification', 'toast', 'Creating initial git commit ...') plugin.call('notification', 'toast', 'Creating initial git commit ...')
await plugin.call('dGitProvider', 'init') await dgitPlugin.call('dgitApi', 'init')
if (!isEmpty) await loadWorkspacePreset(workspaceTemplateName, opts) if (!isEmpty) await loadWorkspacePreset(workspaceTemplateName, opts)
const status = await plugin.call('dGitProvider', 'status', { ref: 'HEAD' }) const status = await dgitPlugin.call('dgitApi', 'status', { ref: 'HEAD' })
Promise.all( Promise.all(
status.map(([filepath, , worktreeStatus]) => status.map(([filepath, , worktreeStatus]) =>
worktreeStatus worktreeStatus
? plugin.call('dGitProvider', 'add', { ? dgitPlugin.call('dgitApi', 'add', {
filepath: removeSlash(filepath), filepath: removeSlash(filepath),
}) })
: plugin.call('dGitProvider', 'rm', { : dgitPlugin.call('dgitApi', 'rm', {
filepath: removeSlash(filepath), filepath: removeSlash(filepath),
}) })
) )
).then(async () => { ).then(async () => {
await plugin.call('dGitProvider', 'commit', { await dgitPlugin.call('dgitApi', 'commit', {
author: { author: {
name, name,
email, email,
@ -225,7 +227,7 @@ export const createWorkspaceTemplate = async (workspaceName: string, template: W
if ((await workspaceExists(workspaceName)) && template === 'remixDefault') throw new Error('workspace already exists') if ((await workspaceExists(workspaceName)) && template === 'remixDefault') throw new Error('workspace already exists')
else if (metadata && metadata.type === 'git') { else if (metadata && metadata.type === 'git') {
dispatch(cloneRepositoryRequest()) dispatch(cloneRepositoryRequest())
await plugin.call('dGitProvider', 'clone', { url: metadata.url, branch: metadata.branch }, workspaceName) await dgitPlugin.call('dgitApi', 'clone', { url: metadata.url, branch: metadata.branch, workspaceName: workspaceName })
dispatch(cloneRepositorySuccess()) dispatch(cloneRepositorySuccess())
} else { } else {
const workspaceProvider = plugin.fileProviders.workspace const workspaceProvider = plugin.fileProviders.workspace
@ -649,11 +651,11 @@ export const getWorkspaces = async (): Promise<{ name: string; isGitRepo: boolea
export const cloneRepository = async (url: string) => { export const cloneRepository = async (url: string) => {
const config = plugin.registry.get('config').api const config = plugin.registry.get('config').api
const token = config.get('settings/gist-access-token') const token = config.get('settings/gist-access-token')
const repoConfig = { url, token } const repoConfig: cloneInputType = { url, token }
if (plugin.registry.get('platform').api.isDesktop()) { if (plugin.registry.get('platform').api.isDesktop()) {
try { try {
await plugin.call('dGitProvider', 'clone', repoConfig) await dgitPlugin.call('dgitApi', 'clone', repoConfig)
} catch (e) { } catch (e) {
console.log(e) console.log(e)
plugin.call('notification', 'alert', { plugin.call('notification', 'alert', {
@ -666,7 +668,7 @@ export const cloneRepository = async (url: string) => {
const repoName = await getRepositoryTitle(url) const repoName = await getRepositoryTitle(url)
await createWorkspace(repoName, 'blank', null, true, null, true, false) await createWorkspace(repoName, 'blank', null, true, null, true, false)
const promise = plugin.call('dGitProvider', 'clone', repoConfig, repoName, true) const promise = dgitPlugin.call('dgitApi', 'clone', {...repoConfig, workspaceExists: true, workspaceName: repoName})
dispatch(cloneRepositoryRequest()) dispatch(cloneRepositoryRequest())
promise promise
@ -715,8 +717,8 @@ export const checkGit = async () => {
dispatch(setCurrentWorkspaceIsGitRepo(isGitRepo)) dispatch(setCurrentWorkspaceIsGitRepo(isGitRepo))
dispatch(setCurrentWorkspaceHasGitSubmodules(hasGitSubmodule)) dispatch(setCurrentWorkspaceHasGitSubmodules(hasGitSubmodule))
await refreshBranches() await refreshBranches()
const currentBranch: branch = await plugin.call('dGitProvider', 'currentbranch') const currentBranch: branch = await dgitPlugin.call('dgitApi', 'currentbranch')
dispatch(setCurrentWorkspaceCurrentBranch(currentBranch.name)) dispatch(setCurrentWorkspaceCurrentBranch(currentBranch))
} catch (e) {} } catch (e) {}
} }
@ -744,7 +746,7 @@ export const getGitRepoBranches = async (workspacePath: string) => {
fs: window.remixFileSystemCallback, fs: window.remixFileSystemCallback,
dir: addSlash(workspacePath), dir: addSlash(workspacePath),
} }
const branches: { remote: any; name: string }[] = await plugin.call('dGitProvider', 'branches', { ...gitConfig }) const branches: { remote: any; name: string }[] = await dgitPlugin.call('dgitApi', 'branches', { ...gitConfig })
return branches return branches
} }
@ -753,8 +755,8 @@ export const getGitRepoCurrentBranch = async (workspaceName: string) => {
fs: window.remixFileSystemCallback, fs: window.remixFileSystemCallback,
dir: addSlash(workspaceName), dir: addSlash(workspaceName),
} }
const currentBranch: branch = await plugin.call('dGitProvider', 'currentbranch', { ...gitConfig }) const currentBranch: branch = await dgitPlugin.call('dgitApi', 'currentbranch', { ...gitConfig })
return currentBranch && currentBranch.name return currentBranch
} }
export const showAllBranches = async () => { export const showAllBranches = async () => {
@ -782,7 +784,7 @@ const refreshBranches = async () => {
dispatch(setCurrentWorkspaceBranches(branches)) dispatch(setCurrentWorkspaceBranches(branches))
} }
export const switchBranch = async (branch: string) => { export const switchBranch = async (branch: branch) => {
await plugin.call('fileManager', 'closeAllFiles') await plugin.call('fileManager', 'closeAllFiles')
const localChanges = await hasLocalChanges() const localChanges = await hasLocalChanges()
@ -798,7 +800,7 @@ export const switchBranch = async (branch: string) => {
okFn: async () => { okFn: async () => {
dispatch(cloneRepositoryRequest()) dispatch(cloneRepositoryRequest())
plugin plugin
.call('dGitProvider', 'checkout', { ref: branch, force: true }, false) .call('dgitApi', 'checkout', { ref: branch, force: true }, false)
.then(async () => { .then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH) await fetchWorkspaceDirectory(ROOT_PATH)
dispatch(setCurrentWorkspaceCurrentBranch(branch)) dispatch(setCurrentWorkspaceCurrentBranch(branch))
@ -816,7 +818,7 @@ export const switchBranch = async (branch: string) => {
} else { } else {
dispatch(cloneRepositoryRequest()) dispatch(cloneRepositoryRequest())
plugin plugin
.call('dGitProvider', 'checkout', { ref: branch, force: true }, false) .call('dgitApi', 'checkout', { ref: branch, force: true }, false)
.then(async () => { .then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH) await fetchWorkspaceDirectory(ROOT_PATH)
dispatch(setCurrentWorkspaceCurrentBranch(branch)) dispatch(setCurrentWorkspaceCurrentBranch(branch))
@ -829,13 +831,16 @@ export const switchBranch = async (branch: string) => {
} }
export const createNewBranch = async (branch: string) => { export const createNewBranch = async (branch: string) => {
const promise = plugin.call('dGitProvider', 'branch', { ref: branch, checkout: true }, false) const promise = dgitPlugin.call('dgitApi', 'branch', { ref: branch, checkout: true, refresh: false })
dispatch(cloneRepositoryRequest()) dispatch(cloneRepositoryRequest())
promise promise
.then(async () => { .then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH) await fetchWorkspaceDirectory(ROOT_PATH)
dispatch(setCurrentWorkspaceCurrentBranch(branch)) dispatch(setCurrentWorkspaceCurrentBranch({
remote: null,
name: branch,
}))
const workspacesPath = plugin.fileProviders.workspace.workspacesPath const workspacesPath = plugin.fileProviders.workspace.workspacesPath
const workspaceName = plugin.fileProviders.workspace.workspace const workspaceName = plugin.fileProviders.workspace.workspace
const branches = await getGitRepoBranches(workspacesPath + '/' + workspaceName) const branches = await getGitRepoBranches(workspacesPath + '/' + workspaceName)
@ -881,11 +886,11 @@ export const updateGitSubmodules = async () => {
const config = plugin.registry.get('config').api const config = plugin.registry.get('config').api
const token = config.get('settings/gist-access-token') const token = config.get('settings/gist-access-token')
const repoConfig = { token } const repoConfig = { token }
await plugin.call('dGitProvider', 'updateSubmodules', repoConfig) await dgitPlugin.call('dgitApi', 'updateSubmodules', repoConfig)
dispatch(cloneRepositorySuccess()) dispatch(cloneRepositorySuccess())
} }
export const checkoutRemoteBranch = async (branch: string, remote: string) => { export const checkoutRemoteBranch = async (branch: branch) => {
const localChanges = await hasLocalChanges() const localChanges = await hasLocalChanges()
if (Array.isArray(localChanges) && localChanges.length > 0) { if (Array.isArray(localChanges) && localChanges.length > 0) {
@ -900,7 +905,10 @@ export const checkoutRemoteBranch = async (branch: string, remote: string) => {
okFn: async () => { okFn: async () => {
dispatch(cloneRepositoryRequest()) dispatch(cloneRepositoryRequest())
plugin plugin
.call('dGitProvider', 'checkout', { ref: branch, remote, force: true }, false) .call('dgitApi', 'checkout', {
ref: branch,
force: true,
})
.then(async () => { .then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH) await fetchWorkspaceDirectory(ROOT_PATH)
dispatch(setCurrentWorkspaceCurrentBranch(branch)) dispatch(setCurrentWorkspaceCurrentBranch(branch))
@ -923,7 +931,10 @@ export const checkoutRemoteBranch = async (branch: string, remote: string) => {
} else { } else {
dispatch(cloneRepositoryRequest()) dispatch(cloneRepositoryRequest())
plugin plugin
.call('dGitProvider', 'checkout', { ref: branch, remote, force: true }, false) .call('dgitApi', 'checkout',{
ref: branch,
force: true,
}, false)
.then(async () => { .then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH) await fetchWorkspaceDirectory(ROOT_PATH)
dispatch(setCurrentWorkspaceCurrentBranch(branch)) dispatch(setCurrentWorkspaceCurrentBranch(branch))
@ -956,7 +967,7 @@ export const removeRecentElectronFolder = async (path: string) => {
} }
export const hasLocalChanges = async () => { export const hasLocalChanges = async () => {
const filesStatus = await plugin.call('dGitProvider', 'status') const filesStatus = await dgitPlugin.call('dgitApi', 'status')
const uncommittedFiles = getUncommittedFiles(filesStatus) const uncommittedFiles = getUncommittedFiles(filesStatus)
return uncommittedFiles return uncommittedFiles

@ -1,3 +1,4 @@
import { branch } from '@remix-ui/git'
import { customAction } from '@remixproject/plugin-api' import { customAction } from '@remixproject/plugin-api'
import { createContext, SyntheticEvent } from 'react' import { createContext, SyntheticEvent } from 'react'
import { BrowserState } from '../reducers/workspace' import { BrowserState } from '../reducers/workspace'
@ -40,9 +41,9 @@ export const FileSystemContext = createContext<{
dispatchMoveFile: (src: string, dest: string) => Promise<void>, dispatchMoveFile: (src: string, dest: string) => Promise<void>,
dispatchMoveFolder: (src: string, dest: string) => Promise<void>, dispatchMoveFolder: (src: string, dest: string) => Promise<void>,
dispatchShowAllBranches: () => Promise<void>, dispatchShowAllBranches: () => Promise<void>,
dispatchSwitchToBranch: (branch: string) => Promise<void>, dispatchSwitchToBranch: (branch: branch) => Promise<void>,
dispatchCreateNewBranch: (branch: string) => Promise<void>, dispatchCreateNewBranch: (name: string) => Promise<void>,
dispatchCheckoutRemoteBranch: (branch: string, remote: string) => Promise<void>, dispatchCheckoutRemoteBranch: (branch: branch) => Promise<void>,
dispatchCreateSolidityGithubAction: () => Promise<void>, dispatchCreateSolidityGithubAction: () => Promise<void>,
dispatchCreateTsSolGithubAction: () => Promise<void>, dispatchCreateTsSolGithubAction: () => Promise<void>,
dispatchCreateSlitherGithubAction: () => Promise<void> dispatchCreateSlitherGithubAction: () => Promise<void>

@ -5,6 +5,7 @@ import {Toaster} from '@remix-ui/toaster' // eslint-disable-line
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
import { FileSystemContext } from '../contexts' import { FileSystemContext } from '../contexts'
import { browserReducer, browserInitialState } from '../reducers/workspace' import { browserReducer, browserInitialState } from '../reducers/workspace'
import { branch } from '@remix-ui/git'
import { import {
initWorkspace, initWorkspace,
fetchDirectory, fetchDirectory,
@ -209,7 +210,7 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
await showAllBranches() await showAllBranches()
} }
const dispatchSwitchToBranch = async (branch: string) => { const dispatchSwitchToBranch = async (branch: branch) => {
await switchBranch(branch) await switchBranch(branch)
} }
@ -217,8 +218,8 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
await createNewBranch(branch) await createNewBranch(branch)
} }
const dispatchCheckoutRemoteBranch = async (branch: string, remote: string) => { const dispatchCheckoutRemoteBranch = async (branch: branch) => {
await checkoutRemoteBranch(branch, remote) await checkoutRemoteBranch(branch)
} }
const dispatchCreateSolidityGithubAction = async () => { const dispatchCreateSolidityGithubAction = async () => {

@ -5,6 +5,7 @@ import { fileDecoration } from '@remix-ui/file-decorators'
import { ROOT_PATH } from '../utils/constants' import { ROOT_PATH } from '../utils/constants'
import isElectron from 'is-electron' import isElectron from 'is-electron'
import { fileKeySort } from '../utils' import { fileKeySort } from '../utils'
import { branch } from '@remix-ui/git'
export interface BrowserState { export interface BrowserState {
browser: { browser: {
currentWorkspace: string currentWorkspace: string
@ -12,11 +13,8 @@ export interface BrowserState {
name: string name: string
isGitRepo: boolean isGitRepo: boolean
hasGitSubmodules?: boolean hasGitSubmodules?: boolean
branches?: { branches?: branch[]
remote: any currentBranch?: branch
name: string
}[]
currentBranch?: string
isGist: string isGist: string
}[] }[]
files: {[x: string]: Record<string, FileType>} files: {[x: string]: Record<string, FileType>}

@ -16,6 +16,7 @@ import { customAction } from '@remixproject/plugin-api'
import { appPlatformTypes, platformContext } from '@remix-ui/app' import { appPlatformTypes, platformContext } from '@remix-ui/app'
import { ElectronMenu } from './components/electron-menu' import { ElectronMenu } from './components/electron-menu'
import { ElectronWorkspaceName } from './components/electron-workspace-name' import { ElectronWorkspaceName } from './components/electron-workspace-name'
import { branch } from '@remix-ui/git'
const _paq = (window._paq = window._paq || []) const _paq = (window._paq = window._paq || [])
@ -693,13 +694,14 @@ export function Workspace() {
global.dispatchShowAllBranches() global.dispatchShowAllBranches()
} }
const switchToBranch = async (branch: {remote: string; name: string}) => { const switchToBranch = async (branch: branch) => {
console.log('switchToBranch', branch)
try { try {
if (branch.remote) { if (branch.remote) {
await global.dispatchCheckoutRemoteBranch(branch.name, branch.remote) await global.dispatchCheckoutRemoteBranch(branch)
_paq.push(['trackEvent', 'Workspace', 'GIT', 'checkout_remote_branch']) _paq.push(['trackEvent', 'Workspace', 'GIT', 'checkout_remote_branch'])
} else { } else {
await global.dispatchSwitchToBranch(branch.name) await global.dispatchSwitchToBranch(branch)
_paq.push(['trackEvent', 'Workspace', 'GIT', 'switch_to_exisiting_branch']) _paq.push(['trackEvent', 'Workspace', 'GIT', 'switch_to_exisiting_branch'])
} }
} catch (e) { } catch (e) {
@ -1259,7 +1261,7 @@ export function Workspace() {
}} }}
title={intl.formatMessage({ id: `filePanel.switchToBranch${branch.remote ? 'Title1' : 'Title2'}` })} title={intl.formatMessage({ id: `filePanel.switchToBranch${branch.remote ? 'Title1' : 'Title2'}` })}
> >
<div data-id={`workspaceGit-${branch.remote ? `${branch.remote}/${branch.name}` : branch.name}`}> <div data-id={`workspaceGit-${branch.remote ? `${branch.remote.name}/${branch.name}` : branch.name}`}>
{currentBranch === branch.name && !branch.remote ? ( {currentBranch === branch.name && !branch.remote ? (
<span> <span>
&#10003; <i className="far fa-code-branch"></i> &#10003; <i className="far fa-code-branch"></i>
@ -1268,7 +1270,7 @@ export function Workspace() {
) : ( ) : (
<span className="pl-3"> <span className="pl-3">
<i className={`far ${branch.remote ? 'fa-cloud' : 'fa-code-branch'}`}></i> <i className={`far ${branch.remote ? 'fa-cloud' : 'fa-code-branch'}`}></i>
<span className="pl-1">{branch.remote ? `${branch.remote}/${branch.name}` : branch.name}</span> <span className="pl-1">{branch.remote ? `${branch.remote.name}/${branch.name}` : branch.name}</span>
</span> </span>
)} )}
</div> </div>

@ -6,6 +6,7 @@ import { RemixAppManager } from 'libs/remix-ui/plugin-manager/src/types'
import { ViewPlugin } from '@remixproject/engine-web' import { ViewPlugin } from '@remixproject/engine-web'
import { appPlatformTypes } from '@remix-ui/app' import { appPlatformTypes } from '@remix-ui/app'
import { Placement } from 'react-bootstrap/esm/Overlay' import { Placement } from 'react-bootstrap/esm/Overlay'
import { branch } from '@remix-ui/git'
export type action = { name: string, type?: Array<WorkspaceElement>, path?: string[], extension?: string[], pattern?: string[], id: string, multiselect: boolean, label: string, sticky?: boolean, group: number, platform?: appPlatformTypes } export type action = { name: string, type?: Array<WorkspaceElement>, path?: string[], extension?: string[], pattern?: string[], id: string, multiselect: boolean, label: string, sticky?: boolean, group: number, platform?: appPlatformTypes }
export interface JSONStandardInput { export interface JSONStandardInput {
@ -51,7 +52,7 @@ export type WorkspaceMetadata = {
name: string name: string
isGitRepo: boolean isGitRepo: boolean
hasGitSubmodules?: boolean hasGitSubmodules?: boolean
branches?: {remote: any; name: string}[] branches?: branch[]
currentBranch?: string currentBranch?: string
isGist: string isGist: string
} }
@ -244,14 +245,14 @@ export interface ActionPayloadTypes {
SET_CURRENT_WORKSPACE: { SET_CURRENT_WORKSPACE: {
name: string name: string
isGitRepo: boolean isGitRepo: boolean
branches?: {remote: string | undefined; name: string}[] branches?: branch[]
currentBranch?: string currentBranch?: branch
}, },
SET_WORKSPACES: { SET_WORKSPACES: {
name: string name: string
isGitRepo: boolean isGitRepo: boolean
branches?: {remote: string | undefined; name: string}[] branches?: branch[]
currentBranch?: string currentBranch?: branch
}[], }[],
SET_MODE: 'browser' | 'localhost', SET_MODE: 'browser' | 'localhost',
FETCH_DIRECTORY_REQUEST: undefined | null, FETCH_DIRECTORY_REQUEST: undefined | null,
@ -293,8 +294,8 @@ export interface ActionPayloadTypes {
CREATE_WORKSPACE_SUCCESS: { CREATE_WORKSPACE_SUCCESS: {
name: string name: string
isGitRepo: boolean isGitRepo: boolean
branches?: { remote: string | undefined; name: string }[] branches?: branch[]
currentBranch?: string currentBranch?: branch
}, },
CREATE_WORKSPACE_ERROR: string, CREATE_WORKSPACE_ERROR: string,
RENAME_WORKSPACE: { oldName: string; workspaceName: string }, RENAME_WORKSPACE: { oldName: string; workspaceName: string },
@ -317,8 +318,8 @@ export interface ActionPayloadTypes {
CLONE_REPOSITORY_FAILED: undefined | null, CLONE_REPOSITORY_FAILED: undefined | null,
FS_INITIALIZATION_COMPLETED: undefined | null, FS_INITIALIZATION_COMPLETED: undefined | null,
SET_FILE_DECORATION_SUCCESS: fileDecoration[], SET_FILE_DECORATION_SUCCESS: fileDecoration[],
SET_CURRENT_WORKSPACE_BRANCHES: { remote: string | undefined; name: string }[], SET_CURRENT_WORKSPACE_BRANCHES: branch[],
SET_CURRENT_WORKSPACE_CURRENT_BRANCH: string, SET_CURRENT_WORKSPACE_CURRENT_BRANCH: branch,
SET_CURRENT_WORKSPACE_IS_GITREPO: boolean, SET_CURRENT_WORKSPACE_IS_GITREPO: boolean,
SET_CURRENT_WORKSPACE_HAS_GIT_SUBMODULES: boolean, SET_CURRENT_WORKSPACE_HAS_GIT_SUBMODULES: boolean,
SET_GIT_CONFIG: { SET_GIT_CONFIG: {

Loading…
Cancel
Save