From 8695d259bfe4123c66ce87ecff75acbd66c493b9 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 6 Jun 2024 15:15:12 +0200 Subject: [PATCH] fixes --- .../remix-ide-e2e/src/tests/vyper_api.test.ts | 8 +-- apps/remix-ide/src/app/files/dgitProvider.ts | 8 +-- apps/vyper/src/app/utils/remix-client.tsx | 12 ++++- apps/vyper/src/main.tsx | 4 +- .../editor/src/lib/remix-ui-editor.tsx | 1 - .../git/src/components/branchHeader.tsx | 46 +++++++++++++++-- libs/remix-ui/git/src/components/gitui.tsx | 21 +++++--- .../git/src/components/panels/branches.tsx | 50 +++++++++---------- .../panels/branches/localbranchdetails.tsx | 9 ++-- .../panels/branches/remotebranchedetails.tsx | 11 +++- libs/remix-ui/git/src/lib/gitactions.ts | 27 +++++++--- libs/remix-ui/git/src/lib/listeners.ts | 3 ++ libs/remix-ui/git/src/state/actions.ts | 1 + libs/remix-ui/git/src/state/context.tsx | 1 + libs/remix-ui/git/src/state/gitpayload.ts | 7 +++ libs/remix-ui/git/src/state/gitreducer.tsx | 6 +++ libs/remix-ui/git/src/types/index.ts | 11 +++- .../workspace/src/lib/actions/index.ts | 1 - 18 files changed, 165 insertions(+), 62 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/vyper_api.test.ts b/apps/remix-ide-e2e/src/tests/vyper_api.test.ts index c2f29519bc..356752a56a 100644 --- a/apps/remix-ide-e2e/src/tests/vyper_api.test.ts +++ b/apps/remix-ide-e2e/src/tests/vyper_api.test.ts @@ -40,7 +40,7 @@ module.exports = { .openFile('src') .openFile('src/snekmate') .openFile('src/snekmate/tokens') - .openFile('src/snekmate/tokens/erc721.vy') + .openFile('src/snekmate/tokens/ERC721.vy') }, // 'Add vyper file to run tests #group1': function (browser: NightwatchBrowser) { // browser.addFile('TestBallot.sol', sources[0]['TestBallot.sol']) @@ -149,7 +149,7 @@ module.exports = { }) }, - 'Compile Ownable contract from snekmate #group1': !function (browser: NightwatchBrowser) { + 'Compile Ownable contract from snekmate #group1': function (browser: NightwatchBrowser) { let contractAddress browser .frameParent() @@ -158,8 +158,8 @@ module.exports = { .openFile('src') .openFile('src/snekmate') .openFile('src/snekmate/auth') - .openFile('src/snekmate/auth/ownable.vy') - .rightClick('*[data-id="treeViewLitreeViewItemsrc/snekmate/auth/ownable.vy"]') + .openFile('src/snekmate/auth/Ownable.vy') + .rightClick('*[data-id="treeViewLitreeViewItemsrc/snekmate/auth/Ownable.vy"]') .waitForElementVisible('*[data-id="contextMenuItemvyper"]') .click('*[data-id="contextMenuItemvyper"]') .clickLaunchIcon('vyper') diff --git a/apps/remix-ide/src/app/files/dgitProvider.ts b/apps/remix-ide/src/app/files/dgitProvider.ts index 2e16ea6c04..61870c64c0 100644 --- a/apps/remix-ide/src/app/files/dgitProvider.ts +++ b/apps/remix-ide/src/app/files/dgitProvider.ts @@ -446,6 +446,7 @@ class DGitProvider extends Plugin { } return branches } catch (e) { + console.log(e) return [] } } @@ -803,7 +804,7 @@ class DGitProvider extends Plugin { relative: input.relative, input } - console.log('fetch input', cmd) + let result if ((Registry.getInstance().get('platform').api.isDesktop())) { result = await this.call('isogit', 'fetch', cmd) @@ -816,7 +817,7 @@ class DGitProvider extends Plugin { ...await this.addIsomorphicGitConfigFS(), ...cmd2 }) - console.log('fetch result', cmd2, result) + } setTimeout(async () => { @@ -1066,7 +1067,6 @@ class DGitProvider extends Plugin { readCommitResults.push(readCommitResult) } - console.log(readCommitResults) // Check for the Link header to determine pagination const linkHeader = response.headers.link; @@ -1077,7 +1077,7 @@ class DGitProvider extends Plugin { hasNextPage = linkHeader.includes('rel="next"'); } - console.log("Has next page:", hasNextPage); + pages.push({ page: input.page, perPage: input.length, diff --git a/apps/vyper/src/app/utils/remix-client.tsx b/apps/vyper/src/app/utils/remix-client.tsx index 38bc35d7d9..91bfc41ed2 100644 --- a/apps/vyper/src/app/utils/remix-client.tsx +++ b/apps/vyper/src/app/utils/remix-client.tsx @@ -86,7 +86,17 @@ export class RemixClient extends PluginClient { await this.call( 'dgitApi', 'clone', - {url: 'https://github.com/pcaversaccio/snekmate', token: null, branch: 'main', singleBranch: true, workspaceName: 'snekmate'}, + {url: 'https://github.com/pcaversaccio/snekmate', token: null, branch: 'main', singleBranch: false, workspaceName: 'snekmate'}, + ) + + await this.call( + 'dgitApi', + 'checkout', + { + ref:'v0.0.5', + force: true, + refresh: true, + } ) this.call( diff --git a/apps/vyper/src/main.tsx b/apps/vyper/src/main.tsx index 374becdd57..cc6581c6be 100644 --- a/apps/vyper/src/main.tsx +++ b/apps/vyper/src/main.tsx @@ -6,8 +6,8 @@ import App from './app/app' const container = document.getElementById('root'); if (container) { - createRoot(container).render( + createRoot(container).render( - ); + ); } diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index f3299d1f7a..320e71477b 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -332,7 +332,6 @@ export const EditorUI = (props: EditorUIProps) => { }) useEffect(() => { - console.log(props.isDiff, props.currentFile) if (!(editorRef.current || diffEditorRef.current ) || !props.currentFile) return currentFileRef.current = props.currentFile props.plugin.call('fileManager', 'getUrlFromPath', currentFileRef.current).then((url) => (currentUrlRef.current = url.file)) diff --git a/libs/remix-ui/git/src/components/branchHeader.tsx b/libs/remix-ui/git/src/components/branchHeader.tsx index 189144aa62..debb86bd5a 100644 --- a/libs/remix-ui/git/src/components/branchHeader.tsx +++ b/libs/remix-ui/git/src/components/branchHeader.tsx @@ -1,17 +1,39 @@ -import React, { useEffect, useReducer, useState } from 'react' -import { gitActionsContext } from '../state/context' +import React, { useEffect, useState } from 'react' +import { gitActionsContext, pluginActionsContext } from '../state/context' +import { ReadCommitResult } from "isomorphic-git" import { gitPluginContext } from './gitui' export const BranchHeader = () => { const context = React.useContext(gitPluginContext) const actions = React.useContext(gitActionsContext) + const pluginActions = React.useContext(pluginActionsContext) const [changed, setChanged] = useState(false) + const [isDetached, setIsDetached] = useState(false) + const [latestCommit, setLatestCommit] = useState(null) useEffect(() => { if (context.currentBranch) { actions.getBranchDifferences(context.currentBranch, null, context) } - }, [context.currentBranch, context.commits, context.branches, context.remotes]) + if (!context.currentBranch || (context.currentBranch && context.currentBranch.name === '')) { + if (context.currentHead === '') { + setIsDetached(false) + } else { + setIsDetached(true) + } + } else { + setIsDetached(false) + } + setLatestCommit(null) + if (context.currentHead !== '') { + if (context.commits && context.commits.length > 0) { + const commit = context.commits.find(commit => commit.oid === context.currentHead) + if (commit) { + setLatestCommit(commit) + } + } + } + }, [context.currentBranch, context.commits, context.branches, context.remotes, context.currentHead]) useEffect(() => { if (context.fileStatusResult) { @@ -21,11 +43,27 @@ export const BranchHeader = () => { } }, [context.fileStatusResult, context.modified, context.allchangesnotstaged, context.untracked, context.deleted]) + const showDetachedWarningText = async () => { + await pluginActions.showAlert({ + message: `You are in 'detached HEAD' state. This means you are not on a branch because you checkout a tag or a specific commit. If you want to commit changes, you will need to create a new branch.`, + title: 'Warning' + }) + } + return (<>
- {changed?'*':''}{context.currentBranch && context.currentBranch.name}
+ {changed ? '*' : ''}{context.currentBranch && context.currentBranch.name} +
+ {latestCommit ? +
+ {latestCommit.commit && latestCommit.commit.message ? latestCommit.commit.message : ''} +
: null} + {isDetached ? +
+ You are in a detached state +
: null}
) diff --git a/libs/remix-ui/git/src/components/gitui.tsx b/libs/remix-ui/git/src/components/gitui.tsx index e169e0bec9..03df19ff65 100644 --- a/libs/remix-ui/git/src/components/gitui.tsx +++ b/libs/remix-ui/git/src/components/gitui.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useReducer, useState } from 'react' -import { add, addall, checkout, checkoutfile, clone, commit, createBranch, remoteBranches, repositories, rm, getCommitChanges, diff, resolveRef, getBranchCommits, setUpstreamRemote, loadGitHubUserFromToken, getBranches, getRemotes, remoteCommits, saveGitHubCredentials, getGitHubCredentialsFromLocalStorage, fetch, pull, push, setDefaultRemote, addRemote, removeRemote, sendToGitLog, clearGitLog, getBranchDifferences, getFileStatusMatrix, init } from '../lib/gitactions' +import { add, addall, checkout, checkoutfile, clone, commit, createBranch, remoteBranches, repositories, rm, getCommitChanges, diff, resolveRef, getBranchCommits, setUpstreamRemote, loadGitHubUserFromToken, getBranches, getRemotes, remoteCommits, saveGitHubCredentials, getGitHubCredentialsFromLocalStorage, fetch, pull, push, setDefaultRemote, addRemote, removeRemote, sendToGitLog, clearGitLog, getBranchDifferences, getFileStatusMatrix, init, showAlert } from '../lib/gitactions' import { loadFiles, setCallBacks } from '../lib/listeners' import { openDiff, openFile, saveToken, setModifiedDecorator, setPlugin, setUntrackedDecorator, statusChanged } from '../lib/pluginActions' import { gitActionsContext, pluginActionsContext } from '../state/context' @@ -52,14 +52,14 @@ export const GitUI = (props: IGitUi) => { useEffect(() => { plugin.emit('statusChanged', { - key:'loading', + key: 'loading', type: 'info', title: 'Loading Git Plugin' }) setTimeout(() => { setAppLoaded(true) }, 2000) - },[]) + }, []) useEffect(() => { if (!appLoaded) return @@ -108,9 +108,14 @@ export const GitUI = (props: IGitUi) => { updatestate() }) - setNeedsInit(!(gitState.currentBranch && gitState.currentBranch.name !== '')) + let needsInit = false + if (!(gitState.currentBranch && gitState.currentBranch.name !== '') && gitState.currentHead === '') { + needsInit = true + } + + setNeedsInit(needsInit) - }, [gitState.gitHubUser, gitState.currentBranch, gitState.remotes, gitState.gitHubAccessToken]) + }, [gitState.gitHubUser, gitState.currentBranch, gitState.remotes, gitState.gitHubAccessToken, gitState.currentHead]) const gitActionsProviderValue = { commit, @@ -151,7 +156,8 @@ export const GitUI = (props: IGitUi) => { openDiff, saveToken, saveGitHubCredentials, - getGitHubCredentialsFromLocalStorage + getGitHubCredentialsFromLocalStorage, + showAlert } return ( @@ -159,8 +165,9 @@ export const GitUI = (props: IGitUi) => { - + + {setup && !needsInit ? : null} {needsInit ? : null} {!setup && !needsInit ? diff --git a/libs/remix-ui/git/src/components/panels/branches.tsx b/libs/remix-ui/git/src/components/panels/branches.tsx index a609782201..ecffd92c2b 100644 --- a/libs/remix-ui/git/src/components/panels/branches.tsx +++ b/libs/remix-ui/git/src/components/panels/branches.tsx @@ -16,14 +16,6 @@ export const Branches = () => { setNewBranch({ value: e.currentTarget.value }); }; - const checkout = async (oid: string, remote: remote) => { - try { - actions.checkout({ ref: oid, remote: remote.name }); - } catch (e) { - // do nothing - } - }; - return ( <>
@@ -35,25 +27,31 @@ export const Branches = () => { ); })}
- -
- -
- actions.createBranch(newBranch.value)} - className="btn w-md-25 w-100 btn-primary" - id="createbranch-btn" - > - create new branch - -
:
No branches
} + : null} + {context.currentBranch + && context.currentBranch.name !== '' + && (!context.branches || context.branches.length === 0) ? +
Current branch is `{context.currentBranch.name}` but you have no commits.
+ : null} + +
+ + +
+ actions.createBranch(newBranch.value)} + className="btn w-md-25 w-100 btn-primary" + id="createbranch-btn" + > + create new branch + ); diff --git a/libs/remix-ui/git/src/components/panels/branches/localbranchdetails.tsx b/libs/remix-ui/git/src/components/panels/branches/localbranchdetails.tsx index 3e93858d14..7e292dae3a 100644 --- a/libs/remix-ui/git/src/components/panels/branches/localbranchdetails.tsx +++ b/libs/remix-ui/git/src/components/panels/branches/localbranchdetails.tsx @@ -35,7 +35,8 @@ export const LocalBranchDetails = (props: BrancheDetailsProps) => { const checkout = (branch: branch) => { actions.checkout({ ref: branch.name, - remote: branch.remote && branch.remote.name || null + remote: branch.remote && branch.remote.name || null, + refresh: true }); } @@ -45,11 +46,11 @@ export const LocalBranchDetails = (props: BrancheDetailsProps) => { const checkoutCommit = async (oid: string) => { try { - //await ModalRef.current?.show(); + actions.checkout({ ref: oid }) - //Utils.log("yes"); + ; } catch (e) { - //Utils.log("no"); + // } }; diff --git a/libs/remix-ui/git/src/components/panels/branches/remotebranchedetails.tsx b/libs/remix-ui/git/src/components/panels/branches/remotebranchedetails.tsx index 988b8641e7..68fa141133 100644 --- a/libs/remix-ui/git/src/components/panels/branches/remotebranchedetails.tsx +++ b/libs/remix-ui/git/src/components/panels/branches/remotebranchedetails.tsx @@ -46,9 +46,18 @@ export const RemoteBranchDetails = (props: BrancheDetailsProps) => { }, [context.remoteBranchCommits]) const checkout = async (branch: branch) => { + await actions.fetch({ + remote: branch.remote, + ref: branch, + depth: 20, + singleBranch: true, + relative: false, + quiet: true + }) await actions.checkout({ ref: branch.name, - remote: branch.remote && branch.remote.name || null + remote: branch.remote && branch.remote.name || null, + refresh: true }); await actions.getBranches() } diff --git a/libs/remix-ui/git/src/lib/gitactions.ts b/libs/remix-ui/git/src/lib/gitactions.ts index fae76f0584..a69a80b329 100644 --- a/libs/remix-ui/git/src/lib/gitactions.ts +++ b/libs/remix-ui/git/src/lib/gitactions.ts @@ -1,6 +1,6 @@ import { ReadBlobResult, ReadCommitResult } from "isomorphic-git"; import React from "react"; -import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog, setUserEmails } from "../state/gitpayload"; +import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog, setUserEmails, setCurrenHead } from "../state/gitpayload"; import { GitHubUser, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult, customGitApi, IGitApi, cloneInputType, fetchInputType, pullInputType, pushInputType, checkoutInput, rmInput, addInput, repository, userEmails } from '../types'; import { removeSlash } from "../utils"; import { disableCallBacks, enableCallBacks } from "./listeners"; @@ -107,13 +107,22 @@ export const gitlog = async () => { export const showCurrentBranch = async () => { try { const branch = await currentBranch(); - dispatch(setCanCommit((branch && branch.name !== ""))); dispatch(setCurrentBranch(branch)); + } catch (e) { + console.log(e) + dispatch(setCanCommit(false)); + dispatch(setCurrentBranch({ name: "", remote: { name: "", url: "" } })); + } + try { + const currentHead = await getCommitFromRef('HEAD'); + dispatch(setCurrenHead(currentHead)); } catch (e) { - // show empty branch + console.log(e) + dispatch(setCurrenHead('')); } + } export const currentBranch = async () => { @@ -133,8 +142,7 @@ export const currentBranch = async () => { export const createBranch = async (name: string = "") => { dispatch(setLoading(true)) if (name) { - await plugin.call('dgitApi', 'branch', { ref: name }); - await plugin.call('dgitApi', 'checkout', { ref: name }); + await plugin.call('dgitApi', 'branch', { ref: name, force: true, checkout: true }); } dispatch(setLoading(false)) } @@ -272,8 +280,8 @@ export const checkout = async (cmd: checkoutInput) => { await plugin.call('fileManager', 'closeAllFiles') try { await plugin.call('dgitApi', 'checkout', cmd) - gitlog(); } catch (e) { + console.log(e) plugin.call('notification', 'toast', `${e}`) } await enableCallBacks(); @@ -536,6 +544,13 @@ export const getGitHubCredentialsFromLocalStorage = async () => { } } +export const showAlert = async ({ title, message }: { title: string, message: string }) => { + await plugin.call('notification', 'alert', { + title: title, + message: message + }) +} + export const loadGitHubUserFromToken = async () => { if (!plugin) return try { diff --git a/libs/remix-ui/git/src/lib/listeners.ts b/libs/remix-ui/git/src/lib/listeners.ts index 0c6b2299ec..50a05198ee 100644 --- a/libs/remix-ui/git/src/lib/listeners.ts +++ b/libs/remix-ui/git/src/lib/listeners.ts @@ -120,6 +120,9 @@ export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch { gitlog() }, 10) + loadFileQueue.enqueue(async () => { + getBranches() + }, 20) gitDispatch(setLog({ message: 'Committed changes...', type: 'success' diff --git a/libs/remix-ui/git/src/state/actions.ts b/libs/remix-ui/git/src/state/actions.ts index 99e7fed793..4d35aa1b8c 100644 --- a/libs/remix-ui/git/src/state/actions.ts +++ b/libs/remix-ui/git/src/state/actions.ts @@ -7,6 +7,7 @@ export interface ActionPayloadTypes { SET_COMMITS: ReadCommitResult[] SET_BRANCHES: branch[] SET_CURRENT_BRANCH: branch + SET_CURRENT_HEAD: string SET_CAN_USE_APP: boolean SET_REPO_NAME: string SET_LOADING: boolean diff --git a/libs/remix-ui/git/src/state/context.tsx b/libs/remix-ui/git/src/state/context.tsx index a1629fb0c3..4bd641eb54 100644 --- a/libs/remix-ui/git/src/state/context.tsx +++ b/libs/remix-ui/git/src/state/context.tsx @@ -52,6 +52,7 @@ export interface pluginActions { email: string token: string }> + showAlert({ title, message }:{title: string, message: string}): Promise } export const pluginActionsContext = React.createContext(null) \ No newline at end of file diff --git a/libs/remix-ui/git/src/state/gitpayload.ts b/libs/remix-ui/git/src/state/gitpayload.ts index 130c78a52e..c075331d6e 100644 --- a/libs/remix-ui/git/src/state/gitpayload.ts +++ b/libs/remix-ui/git/src/state/gitpayload.ts @@ -101,6 +101,13 @@ export const setCurrentBranch = (currentBranch: branch) => { } } +export const setCurrenHead = (currentHead: string) => { + return { + type: 'SET_CURRENT_HEAD', + payload: currentHead + } +} + export const setCanCommit = (canCommit: boolean) => { return { type: 'SET_CAN_COMMIT', diff --git a/libs/remix-ui/git/src/state/gitreducer.tsx b/libs/remix-ui/git/src/state/gitreducer.tsx index af56a5e03b..674e1e69a5 100644 --- a/libs/remix-ui/git/src/state/gitreducer.tsx +++ b/libs/remix-ui/git/src/state/gitreducer.tsx @@ -56,6 +56,12 @@ export const gitReducer = (state: gitState = defaultGitState, action: Actions): currentBranch: action.payload } + case 'SET_CURRENT_HEAD': + return { + ...state, + currentHead: action.payload + } + case 'SET_CAN_USE_APP': return { ...state, diff --git a/libs/remix-ui/git/src/types/index.ts b/libs/remix-ui/git/src/types/index.ts index 14e268cde1..795646b84d 100644 --- a/libs/remix-ui/git/src/types/index.ts +++ b/libs/remix-ui/git/src/types/index.ts @@ -82,6 +82,7 @@ export type branchInputType = { ref: string, checkout?: boolean refresh?: boolean + force?: boolean } export type currentBranchInput = { @@ -94,6 +95,7 @@ export type checkoutInput = { force?: boolean, remote?: string refresh?: boolean + fetch?: boolean } export type addInput = { @@ -151,6 +153,7 @@ export interface customGitApi extends IRemixApi { export type gitState = { currentBranch: branch + currentHead: string commits: ReadCommitResult[] branch: string canCommit: boolean @@ -264,6 +267,7 @@ export type remoteBranch = { export const defaultGitState: gitState = { currentBranch: { name: "", remote: { name: "", url: "" } }, + currentHead: "", commits: [], branch: "", canCommit: true, @@ -370,6 +374,11 @@ export interface setCurrentBranchAction { payload: branch } +export interface setCurrentHeadAction { + type: string, + payload: string +} + export interface setRemotesAction { type: string, payload: remote[] @@ -424,4 +433,4 @@ export interface clearLogAction { type: string } -export type gitActionDispatch = clearLogAction | setLogAction | setDefaultRemoteAction | setTokenAction | setUpstreamAction | setRemoteBranchCommitsAction | setLocalBranchCommitsAction | setBranchDifferencesAction | setRemotesAction | setCurrentBranchAction | fileStatusAction | setLoadingAction | setCanUseAppAction | setRepoNameAction | setCommitsAction | setBranchesAction | setReposAction | setRemoteBranchesAction \ No newline at end of file +export type gitActionDispatch = setCurrentHeadAction | clearLogAction | setLogAction | setDefaultRemoteAction | setTokenAction | setUpstreamAction | setRemoteBranchCommitsAction | setLocalBranchCommitsAction | setBranchDifferencesAction | setRemotesAction | setCurrentBranchAction | fileStatusAction | setLoadingAction | setCanUseAppAction | setRepoNameAction | setCommitsAction | setBranchesAction | setReposAction | setRemoteBranchesAction \ No newline at end of file diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index 4608ff9555..d15cfea28b 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -60,7 +60,6 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. let filePathToOpen = null let workspaces = [] plugin.on('editor', 'editorMounted', async () => { - console.log('editor mounted') editorMounted = true if (filePathToOpen){ setTimeout(async () => {