Merge pull request #4233 from ethereum/recursivesubmodule

Recursivesubmodule
pull/4229/head
yann300 1 year ago committed by GitHub
commit 9204b6c577
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 97
      apps/remix-ide-e2e/src/tests/workspace_git.test.ts
  2. 37
      apps/remix-ide/src/app/files/dgitProvider.js
  3. 19
      apps/remix-ide/src/app/files/fileProvider.js
  4. 5
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  5. 2
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -255,5 +255,98 @@ module.exports = {
// GIT BRANCHES E2E END
tearDown: sauce
}
// 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
`

@ -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
}
}

@ -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)

@ -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()
}

@ -1136,7 +1136,7 @@ export function Workspace() {
{selectedWorkspace.hasGitSubmodules?
<div className="pt-1 mr-1">
{global.fs.browser.isRequestingCloning ? <div style={{ height: 30 }} className='btn btn-sm border text-muted small'><i className="fad fa-spinner fa-spin"></i> updating submodules</div> :
<div style={{ height: 30 }} onClick={updateSubModules} className='btn btn-sm border text-muted small'>update submodules</div>}
<div style={{ height: 30 }} onClick={updateSubModules} data-id='updatesubmodules' className='btn btn-sm border text-muted small'>update submodules</div>}
</div>
: null}
<div className="pt-1 mr-1" data-id="workspaceGitBranchesDropdown">

Loading…
Cancel
Save