From f9277301715d90b07cc30117428ab1ad2c5ca004 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 26 Jun 2023 17:26:36 +0200 Subject: [PATCH] fixes for git --- apps/remix-ide/src/app/files/dgitProvider.js | 17 ++++++++++++- apps/remix-ide/src/remixAppManager.js | 5 ++-- apps/remixdesktop/src/plugins/fsPlugin.ts | 24 +++++++++++++++++-- apps/remixdesktop/src/plugins/isoGitPlugin.ts | 23 ++++++++++++++++-- apps/remixdesktop/src/tools/git.ts | 2 +- .../search/src/lib/context/context.tsx | 4 ++++ .../workspace/src/lib/actions/workspace.ts | 2 +- 7 files changed, 68 insertions(+), 9 deletions(-) diff --git a/apps/remix-ide/src/app/files/dgitProvider.js b/apps/remix-ide/src/app/files/dgitProvider.js index 256b7a1203..319ee7c3b1 100644 --- a/apps/remix-ide/src/app/files/dgitProvider.js +++ b/apps/remix-ide/src/app/files/dgitProvider.js @@ -21,7 +21,7 @@ const profile = { description: 'Decentralized git provider', icon: 'assets/img/fileManager.webp', version: '0.0.1', - methods: ['init', 'localStorageUsed', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'export', 'import', 'status', 'log', 'commit', 'add', 'remove', 'rm', 'lsfiles', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pin', 'pull', 'pinList', 'unPin', 'setIpfsConfig', 'zip', 'setItem', 'getItem'], + methods: ['init', 'localStorageUsed', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'export', 'import', 'status', 'log', 'commit', 'add', 'remove', 'reset', 'rm', 'lsfiles', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pin', 'pull', 'pinList', 'unPin', 'setIpfsConfig', 'zip', 'setItem', 'getItem'], kind: 'file-system' } class DGitProvider extends Plugin { @@ -144,6 +144,21 @@ class DGitProvider extends Plugin { } } + + async reset(cmd) { + console.log('rm', cmd) + if (isElectron()) { + await this.call('isogit', 'reset', cmd) + } else { + await git.resetIndex({ + ...await this.getGitConfig(), + ...cmd + }) + this.emit('rm') + + } + } + async checkout(cmd, refresh = true) { if (isElectron()) { diff --git a/apps/remix-ide/src/remixAppManager.js b/apps/remix-ide/src/remixAppManager.js index c51f2e8108..2ffdcc2c40 100644 --- a/apps/remix-ide/src/remixAppManager.js +++ b/apps/remix-ide/src/remixAppManager.js @@ -14,9 +14,9 @@ let requiredModules = [ // services + layout views + system views 'vm-shanghai', 'compileAndRun', 'search', 'recorder', 'fileDecorator', 'codeParser', 'codeFormatter', 'solidityumlgen', 'contractflattener', 'solidity-script'] -if(isElectron()) { +if (isElectron()) { requiredModules = [...requiredModules, 'fs', 'electronTemplates', 'isogit', 'remix-templates', 'electronconfig'] -} +} // dependentModules shouldn't be manually activated (e.g hardhat is activated by remixd) @@ -183,6 +183,7 @@ export class RemixAppManager extends PluginManager { } return plugins.map(plugin => { + if (plugin.name === 'dgit') { plugin.url = 'https://dgit4-76cc9.web.app/' } if (plugin.name === testPluginName) plugin.url = testPluginUrl return new IframePlugin(plugin) }) diff --git a/apps/remixdesktop/src/plugins/fsPlugin.ts b/apps/remixdesktop/src/plugins/fsPlugin.ts index a42db36efc..b1c7a722d4 100644 --- a/apps/remixdesktop/src/plugins/fsPlugin.ts +++ b/apps/remixdesktop/src/plugins/fsPlugin.ts @@ -19,6 +19,10 @@ const convertPathToPosix = (pathName: string): string => { return pathName.split(path.sep).join(path.posix.sep) } +const getBaseName = (pathName: string): string => { + return path.basename(pathName) +} + export class FSPlugin extends ElectronBasePlugin { clients: FSPluginClient[] = [] @@ -81,7 +85,7 @@ const clientProfile: Profile = { name: 'fs', displayName: 'fs', description: 'fs', - methods: ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'currentPath', 'watch', 'closeWatch', 'setWorkingDir', 'openFolder', 'getRecentFolders', 'removeRecentFolder', 'glob', 'openWindow', 'selectFolder'] + methods: ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'currentPath', 'watch', 'closeWatch', 'setWorkingDir', 'openFolder', 'openFolderInSameWindow', 'getRecentFolders', 'removeRecentFolder', 'glob', 'openWindow', 'selectFolder'] } class FSPluginClient extends ElectronBasePluginClient { @@ -341,6 +345,21 @@ class FSPluginClient extends ElectronBasePluginClient { } path = dirs && dirs.length && dirs[0] ? dirs[0] : path if (!path) return + + await this.updateRecentFolders(path) + await this.updateOpenedFolders(path) + this.openWindow(path) + } + + async openFolderInSameWindow(path?: string): Promise { + let dirs: string[] | undefined + if (!path) { + dirs = dialog.showOpenDialogSync(this.window, { + properties: ['openDirectory', 'createDirectory', "showHiddenFiles"] + }) + } + path = dirs && dirs.length && dirs[0] ? dirs[0] : path + if (!path) return this.workingDir = path await this.updateRecentFolders(path) await this.updateOpenedFolders(path) @@ -355,9 +374,10 @@ class FSPluginClient extends ElectronBasePluginClient { this.workingDir = path await this.updateRecentFolders(path) await this.updateOpenedFolders(path) - this.window.setTitle(this.workingDir) + this.window.setTitle(getBaseName(this.workingDir)) this.watch() this.emit('workingDirChanged', path) + await this.call('fileManager', 'closeAllFiles') } fixPath(path: string): string { diff --git a/apps/remixdesktop/src/plugins/isoGitPlugin.ts b/apps/remixdesktop/src/plugins/isoGitPlugin.ts index 05526efbfd..f4e374e154 100644 --- a/apps/remixdesktop/src/plugins/isoGitPlugin.ts +++ b/apps/remixdesktop/src/plugins/isoGitPlugin.ts @@ -46,11 +46,11 @@ const clientProfile: Profile = { name: 'isogit', displayName: 'isogit', description: 'isogit plugin', - methods: ['init', 'localStorageUsed', 'version', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'export', 'import', 'status', 'log', 'commit', 'add', 'remove', 'rm', 'lsfiles', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pin', 'pull', 'pinList', 'unPin', 'setIpfsConfig', 'zip', 'setItem', 'getItem', 'openFolder'] + methods: ['init', 'localStorageUsed', 'version', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'export', 'import', 'status', 'log', 'commit', 'add', 'remove', 'reset', 'rm', 'lsfiles', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pin', 'pull', 'pinList', 'unPin', 'setIpfsConfig', 'zip', 'setItem', 'getItem', 'openFolder'] } class IsoGitPluginClient extends ElectronBasePluginClient { - workingDir: string = '/Volumes/bunsen/code/empty/' + workingDir: string = '' gitIsInstalled: boolean = false constructor(webContentsId: number, profile: Profile) { super(webContentsId, profile) @@ -81,6 +81,10 @@ class IsoGitPluginClient extends ElectronBasePluginClient { async status(cmd: any) { console.log('status', cmd) + if(this.workingDir === ''){ + return [] + } + if(this.gitIsInstalled){ const status = await gitProxy.status(this.workingDir) return status @@ -104,6 +108,10 @@ class IsoGitPluginClient extends ElectronBasePluginClient { } */ + if(this.workingDir === ''){ + return [] + } + console.log('log') const log = await git.log({ ...await this.getGitConfig(), @@ -133,6 +141,17 @@ class IsoGitPluginClient extends ElectronBasePluginClient { return rm } + async reset(cmd: any){ + console.log('reset', cmd) + const reset = await git.resetIndex({ + ...await this.getGitConfig(), + ...cmd + }) + console.log('RESET', reset) + return reset + } + + async commit(cmd: any) { console.log('commit') const commit = await git.commit({ diff --git a/apps/remixdesktop/src/tools/git.ts b/apps/remixdesktop/src/tools/git.ts index e7040597e2..beffb9128a 100644 --- a/apps/remixdesktop/src/tools/git.ts +++ b/apps/remixdesktop/src/tools/git.ts @@ -16,7 +16,7 @@ const statusTransFormMatrix = (status: string) => { case ' M': return [1, 2, 0] case ' D': - return [0, 2, 0] + return [1, 0, 1] case 'D ': return [1, 0, 0] case 'AM': diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index e89adecfc2..5734d7f2b7 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -327,6 +327,10 @@ export const SearchProvider = ({ setFiles(await getDirectory('/', plugin)) }) + plugin.on('fs', 'workingDirChanged', async () => { + setFiles(await getDirectory('/', plugin)) + }) + plugin.on('fileManager', 'fileAdded', async file => { setFiles(await getDirectory('/', plugin)) await reloadStateForFile(file) diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index fac8548517..b07fe6b855 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -775,7 +775,7 @@ export const checkoutRemoteBranch = async (branch: string, remote: string) => { } export const openElectronFolder = async (path: string) => { - await plugin.call('fs', 'openFolder', path) + await plugin.call('fs', 'openFolderInSameWindow', path) } export const getElectronRecentFolders = async () => {