diff --git a/apps/remix-ide-e2e/src/tests/workspace_git.test.ts b/apps/remix-ide-e2e/src/tests/workspace_git.test.ts index 6bc35fe9d4..0a1e1ec63b 100644 --- a/apps/remix-ide-e2e/src/tests/workspace_git.test.ts +++ b/apps/remix-ide-e2e/src/tests/workspace_git.test.ts @@ -255,5 +255,98 @@ module.exports = { // GIT BRANCHES E2E END - tearDown: sauce -} \ No newline at end of file + // GIT SUBMODULES E2E START + + 'Should clone a repository with submodules #group4': function (browser: NightwatchBrowser) { + browser + .clickLaunchIcon('filePanel') + .waitForElementVisible('[data-id="workspaceMenuDropdown"]') + .click('[data-id="workspaceMenuDropdown"]') + .waitForElementVisible('[data-id="workspaceclone"]') + .click('[data-id="workspaceclone"]') + .waitForElementVisible('[data-id="fileSystemModalDialogModalBody-react"]') + .click('[data-id="fileSystemModalDialogModalBody-react"]') + .waitForElementVisible('[data-id="modalDialogCustomPromptTextClone"]') + .setValue('[data-id="modalDialogCustomPromptTextClone"]', 'https://github.com/bunsenstraat/test-branch-submodule') + .click('[data-id="fileSystem-modal-footer-ok-react"]') + .waitForElementPresent('.fa-spinner') + .waitForElementVisible({ + selector: '*[data-id="treeViewLitreeViewItem.git"]', + timeout: 60000 + }) + .waitForElementContainsText('[data-id="workspacesSelect"]', 'test-branch-submodule') + .waitForElementVisible('[data-id="updatesubmodules"]') + .click('[data-id="updatesubmodules"]') + .waitForElementPresent('.fa-spinner') + .waitForElementVisible({ + selector: '*[data-id="treeViewLitreeViewItem.git"]', + timeout: 60000 + }) + .waitForElementVisible('[data-id="treeViewDivtreeViewItemplugins"]') + .waitForElementVisible('[data-id="treeViewDivtreeViewItemwebsite"]') + .waitForElementVisible('[data-id="treeViewDivtreeViewItemrecursive"]') + .pause(2000) + .click('[data-id="treeViewDivtreeViewItemwebsite"]') + .waitForElementVisible('[data-id="treeViewDivtreeViewItemwebsite/index.html"]') + .click('[data-id="treeViewDivtreeViewItemplugins"]') + .waitForElementVisible('[data-id="treeViewDivtreeViewItemplugins/README.md"]') + .click('[data-id="treeViewDivtreeViewItemrecursive"]') + .waitForElementVisible('[data-id="treeViewDivtreeViewItemrecursive/README.md"]') + .waitForElementVisible('[data-id="treeViewDivtreeViewItemrecursive/plugins"]') + .click('[data-id="treeViewDivtreeViewItemrecursive/plugins"]') + .waitForElementVisible('[data-id="treeViewDivtreeViewItemrecursive/plugins/build"]') + }, + 'When switching branches the submodules should dissappear #group4': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('[data-id="workspaceGitBranchesDropdown"]') + .click('[data-id="workspaceGitBranchesDropdown"]') + .waitForElementVisible('[data-id="custom-dropdown-menu"]') + .waitForElementContainsText('[data-id="custom-dropdown-items"]', 'origin/second') + .waitForElementPresent('[data-id="workspaceGit-origin/second"]') + .click('[data-id="workspaceGit-origin/second"]') + .waitForElementNotPresent('[data-id="treeViewDivtreeViewItemplugins"]') + .waitForElementNotPresent('[data-id="treeViewDivtreeViewItemwebsite"]') + }, + 'When switching to main update the modules #group4': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('[data-id="workspaceGitBranchesDropdown"]') + .click('[data-id="workspaceGitBranchesDropdown"]') + .waitForElementVisible('[data-id="custom-dropdown-menu"]') + .waitForElementContainsText('[data-id="custom-dropdown-items"]', 'origin/main') + .waitForElementPresent('[data-id="workspaceGit-origin/main"]') + .click('[data-id="workspaceGit-origin/main"]') + .waitForElementVisible('[data-id="updatesubmodules"]') + .click('[data-id="updatesubmodules"]') + .waitForElementPresent('.fa-spinner') + .waitForElementVisible({ + selector: '*[data-id="treeViewLitreeViewItem.git"]', + timeout: 60000 + }) + .waitForElementVisible('[data-id="treeViewDivtreeViewItemplugins"]') + .waitForElementVisible('[data-id="treeViewDivtreeViewItemwebsite"]') + .pause(2000) + .click('[data-id="treeViewDivtreeViewItemwebsite"]') + .click('[data-id="treeViewDivtreeViewItemwebsite"]') + .waitForElementVisible('[data-id="treeViewDivtreeViewItemwebsite/index.html"]') + .click('[data-id="treeViewDivtreeViewItemplugins"]') + .click('[data-id="treeViewDivtreeViewItemplugins"]') + .waitForElementVisible('[data-id="treeViewDivtreeViewItemplugins/README.md"]') + .click('[data-id="treeViewDivtreeViewItemrecursive"]') + .click('[data-id="treeViewDivtreeViewItemrecursive"]') + .waitForElementVisible('[data-id="treeViewDivtreeViewItemrecursive/README.md"]') + .waitForElementVisible('[data-id="treeViewDivtreeViewItemrecursive/plugins"]') + .click('[data-id="treeViewDivtreeViewItemrecursive/plugins"]') + .waitForElementVisible('[data-id="treeViewDivtreeViewItemrecursive/plugins/build"]') + }, + + tearDown: sauce, +} + + +const gitmodules = `[submodule "subdemo3"] +path = subdemo3 +url = https://github.com/bunsenstraat/empty3 +[submodule "testactionsub"] +path = testactionsub +url = https://github.com/bunsenstraat/testactions +` \ No newline at end of file diff --git a/apps/remix-ide/src/app/files/dgitProvider.js b/apps/remix-ide/src/app/files/dgitProvider.js index 590916f4f0..921e579c75 100644 --- a/apps/remix-ide/src/app/files/dgitProvider.js +++ b/apps/remix-ide/src/app/files/dgitProvider.js @@ -282,9 +282,8 @@ class DGitProvider extends Plugin { ...await this.parseInput(input), ...await this.getGitConfig() } - + this.call('terminal', 'logHtml', `Cloning ${input.url}...`) const result = await git.clone(cmd) - await this.updateSubmodules(input) if (!workspaceExists) { setTimeout(async () => { await this.call('fileManager', 'refresh') @@ -294,9 +293,9 @@ class DGitProvider extends Plugin { return result } - async parseGitmodules () { + async parseGitmodules (dir = '') { try { - const gitmodules = await this.call('fileManager', 'readFile', '.gitmodules') + const gitmodules = await this.call('fileManager', 'readFile', path.join(dir, '.gitmodules')) if (gitmodules) { const lines = gitmodules.split('\n') let currentModule = {} @@ -327,16 +326,19 @@ class DGitProvider extends Plugin { async updateSubmodules(input) { try { - const gitmodules = await this.parseGitmodules() + const currentDir = (input && input.dir) || '' + const gitmodules = await this.parseGitmodules(currentDir) + this.call('terminal', 'logHtml', `Found ${(gitmodules && gitmodules.length) || 0} submodules in ${currentDir || '/'}`) //parse gitmodules if (gitmodules) { for (let module of gitmodules) { - const path = (await this.getGitConfig(module.path)).dir - if (await window.remixFileSystem.exists(path)) { - const stat = await window.remixFileSystem.stat(path) + const dir = path.join(currentDir, module.path) + const targetPath = (await this.getGitConfig(dir)).dir + if (await window.remixFileSystem.exists(targetPath)) { + const stat = await window.remixFileSystem.stat(targetPath) try { if (stat.isDirectory()) { - await window.remixFileSystem.unlink((await this.getGitConfig(module.path)).dir) + await window.remixFileSystem.unlink(targetPath) } } catch (e) { // do nothing @@ -344,18 +346,29 @@ class DGitProvider extends Plugin { } } for (let module of gitmodules) { + const dir = path.join(currentDir, module.path) + // if url contains git@github.com: convert it + if(module.url && module.url.startsWith('git@github.com:')) { + module.url = module.url.replace('git@github.com:', 'https://github.com/') + } try { const cmd = { url: module.url, singleBranch: true, depth: 1, ...await this.parseInput(input), - ...await this.getGitConfig(module.path) + ...await this.getGitConfig(dir) } + this.call('terminal', 'logHtml', `Cloning submodule ${dir}...`) await git.clone(cmd) + this.call('terminal', 'logHtml', `Cloned successfully submodule ${dir}...`) + await this.updateSubmodules({ + ...input, + dir + }) } catch (e) { + this.call('terminal', 'log', { type: 'error', value: `[Cloning]: Error occured! ${e}` }) console.log(e) - } } setTimeout(async () => { @@ -363,7 +376,7 @@ class DGitProvider extends Plugin { }, 1000) } } catch (e) { - console.log(e) + this.call('terminal', 'log', { type: 'error', value: `[Cloning]: Error occured! ${e}` }) // do nothing } } diff --git a/apps/remix-ide/src/app/files/fileProvider.js b/apps/remix-ide/src/app/files/fileProvider.js index 432f6ad45c..91e159ef0e 100644 --- a/apps/remix-ide/src/app/files/fileProvider.js +++ b/apps/remix-ide/src/app/files/fileProvider.js @@ -182,23 +182,8 @@ class FileProvider { if (!stat.isDirectory()) { return await this.removeFile(path) } else { - const items = await window.remixFileSystem.readdir(path) - if (items.length !== 0) { - for (const item of items) { - const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}` - if ((await window.remixFileSystem.stat(curPath)).isDirectory()) { // delete folder - await this.remove(curPath) - } else { // delete file - await this.removeFile(curPath) - } - } - await window.remixFileSystem.rmdir(path) - this.event.emit('fileRemoved', this._normalizePath(path)) - } else { - // folder is empty - await window.remixFileSystem.rmdir(path) - this.event.emit('fileRemoved', this._normalizePath(path)) - } + await window.remixFileSystem.unlink(path) + this.event.emit('fileRemoved', this._normalizePath(path)) } } catch (e) { console.log(e) diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 67a456ca6d..e2d4ed4658 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -78,6 +78,11 @@ export const setPlugin = (filePanelPlugin, reducerDispatch) => { plugin.on('settings', 'configChanged', async () => { await getGitConfig() }) + plugin.on('fileManager', 'fileAdded', async (filePath: string) => { + if(filePath.includes('.gitmodules')) { + await checkGit() + } + }) getGitConfig() } diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index c1e5f9baab..1e203d994d 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -1136,7 +1136,7 @@ export function Workspace() { {selectedWorkspace.hasGitSubmodules?