diff --git a/apps/remix-ide/src/app/files/dgitProvider.ts b/apps/remix-ide/src/app/files/dgitProvider.ts index d754bc2b2d..327990a6ee 100644 --- a/apps/remix-ide/src/app/files/dgitProvider.ts +++ b/apps/remix-ide/src/app/files/dgitProvider.ts @@ -303,14 +303,14 @@ class DGitProvider extends Plugin { } async getCommitChanges(commitHash1, commitHash2): Promise { - //console.log([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({ ...await this.addIsomorphicGitConfigFS(), trees: [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })], map: async function (filepath, [A, B]) { // ignore directories - //console.log(filepath, A, B) + console.log(filepath, A, B) if (filepath === '.') { return @@ -333,6 +333,8 @@ class DGitProvider extends Plugin { path: filepath, } + console.log('Aoid', Aoid, 'Boid', Boid, commitChange) + // determine modification type if (Aoid !== Boid) { commitChange.type = "modified" @@ -340,7 +342,7 @@ class DGitProvider extends Plugin { if (Aoid === undefined) { commitChange.type = "deleted" } - if (Boid === undefined) { + if (Boid === undefined || !commitHash2) { commitChange.type = "added" } if (Aoid === undefined && Boid === undefined) { diff --git a/libs/remix-ui/git/src/components/buttons/gituibutton.tsx b/libs/remix-ui/git/src/components/buttons/gituibutton.tsx index 8a80eab54c..1f34ace69f 100644 --- a/libs/remix-ui/git/src/components/buttons/gituibutton.tsx +++ b/libs/remix-ui/git/src/components/buttons/gituibutton.tsx @@ -15,7 +15,7 @@ const GitUIButton = ({children, disabledCondition = false, ...rest }:ButtonWithC const isDisabled = loading || disabledCondition return ( - ); diff --git a/libs/remix-ui/git/src/components/buttons/sourcecontrolbuttons.tsx b/libs/remix-ui/git/src/components/buttons/sourcecontrolbuttons.tsx index 9ec7b56f26..cc2b180d35 100644 --- a/libs/remix-ui/git/src/components/buttons/sourcecontrolbuttons.tsx +++ b/libs/remix-ui/git/src/components/buttons/sourcecontrolbuttons.tsx @@ -50,7 +50,7 @@ export const SourceControlButtons = (props: SourceControlButtonsProps) => { } if (!props.remote) { setRemote(context.defaultRemote) - }else{ + } else { setDefaultRemote() } }, []) @@ -62,7 +62,7 @@ export const SourceControlButtons = (props: SourceControlButtonsProps) => { } if (!props.remote) { setRemote(context.defaultRemote) - }else{ + } else { setDefaultRemote() } }, [context.defaultRemote, context.currentBranch]) @@ -86,19 +86,26 @@ export const SourceControlButtons = (props: SourceControlButtonsProps) => { await actions.push(remote.remote, branch.name) } + const buttonsDisabled = () => { + return context.upstream === '' || context.remotes.length === 0 + } + - return ( - }> - <>{commitsBehind.length} - - }> - <>{commitsAhead.length} - - }> - - - }> - { }} className='btn btn-sm'> - - ) + return ( + + }> + <>{commitsBehind.length} + + }> + <>{commitsAhead.length} + + }> + + + }> + { }} className='btn btn-sm'> + + + + ) } \ No newline at end of file diff --git a/libs/remix-ui/git/src/components/navigation/branchedetails.tsx b/libs/remix-ui/git/src/components/navigation/branchedetails.tsx index 282a337168..bd7674a894 100644 --- a/libs/remix-ui/git/src/components/navigation/branchedetails.tsx +++ b/libs/remix-ui/git/src/components/navigation/branchedetails.tsx @@ -1,6 +1,7 @@ import { faCaretUp, faCaretDown, faCaretRight, faArrowUp, faArrowDown, faArrowRotateRight, faArrowsUpDown, faGlobe, faCheckCircle, faToggleOff, faToggleOn, faSync } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import React, { useContext, useEffect } from "react"; +import { gitActionsContext } from "../../state/context"; import { branch } from "../../types"; import { gitPluginContext } from "../gitui"; @@ -15,6 +16,7 @@ interface BrancheDetailsNavigationProps { export const BrancheDetailsNavigation = (props: BrancheDetailsNavigationProps) => { const { eventKey, activePanel, callback, branch, checkout } = props; const context = React.useContext(gitPluginContext) + const actions = React.useContext(gitActionsContext) const handleClick = () => { if (!callback) return if (activePanel === eventKey) { @@ -28,6 +30,10 @@ export const BrancheDetailsNavigation = (props: BrancheDetailsNavigationProps) = window.open(`${branch.remote.url}/tree/${branch.name}`, '_blank'); } + const reloadBranch = () => { + actions.getBranchCommits(branch, 1) + } + return ( <>
@@ -45,6 +51,9 @@ export const BrancheDetailsNavigation = (props: BrancheDetailsNavigationProps) = checkout(branch)}> } + {branch.remote?.url && <> + reloadBranch()}>} + {branch.remote?.url && <> openRemote()}>}
diff --git a/libs/remix-ui/git/src/components/panels/commands/fetch.tsx b/libs/remix-ui/git/src/components/panels/commands/fetch.tsx index 4b8257185d..94ccae59b2 100644 --- a/libs/remix-ui/git/src/components/panels/commands/fetch.tsx +++ b/libs/remix-ui/git/src/components/panels/commands/fetch.tsx @@ -7,12 +7,15 @@ import { gitPluginContext } from "../../gitui"; export const Fetch = () => { const actions = React.useContext(gitActionsContext) const context = React.useContext(gitPluginContext) - + + const fetchIsDisabled = () => { + return context.upstream === '' || context.remotes.length === 0 + } return ( <>
- actions.fetch()} className="btn btn-primary mr-1">Fetch {context.upstream} - actions.fetch(null, null, context.currentBranch.name, null, true )} className="btn btn-primary">Fetch {context.currentBranch.name} + actions.fetch()} className="btn btn-primary mr-1">Fetch {context.upstream} + actions.fetch(null, null, context.currentBranch.name, null, true )} className="btn btn-primary">Fetch {context.currentBranch.name}
) } \ No newline at end of file diff --git a/libs/remix-ui/git/src/components/panels/commands/merge.tsx b/libs/remix-ui/git/src/components/panels/commands/merge.tsx index e50705553c..dd99e7b41d 100644 --- a/libs/remix-ui/git/src/components/panels/commands/merge.tsx +++ b/libs/remix-ui/git/src/components/panels/commands/merge.tsx @@ -53,6 +53,7 @@ export const Merge = () => { e && onLocalBranchChange(e.value)} theme={selectTheme} styles={selectStyles} @@ -119,6 +125,7 @@ export const PushPull = () => { e && onRemoteChange(e.value)} theme={selectTheme} styles={selectStyles} diff --git a/libs/remix-ui/git/src/components/panels/commits.tsx b/libs/remix-ui/git/src/components/panels/commits.tsx index ad8c3c196a..1a79cc53c7 100644 --- a/libs/remix-ui/git/src/components/panels/commits.tsx +++ b/libs/remix-ui/git/src/components/panels/commits.tsx @@ -34,6 +34,9 @@ export const Commits = () => { await actions.getCommitChanges(commit.oid, commit.commit.parent[0]) } + const fetchIsDisabled = () => { + return context.upstream === '' || context.remotes.length === 0 + } return ( <> @@ -47,7 +50,7 @@ export const Commits = () => { })} - {hasNextPage && Load more} + {hasNextPage && Load more} :
No commits
} diff --git a/libs/remix-ui/git/src/components/panels/remotes.tsx b/libs/remix-ui/git/src/components/panels/remotes.tsx index 254004dcc5..f651b6a621 100644 --- a/libs/remix-ui/git/src/components/panels/remotes.tsx +++ b/libs/remix-ui/git/src/components/panels/remotes.tsx @@ -48,7 +48,7 @@ export const Remotes = () => { onRemoteNameChange(e.target.value)} value={remoteName} className="form-control mb-2" type="text" id="remotename" /> onUrlChange(e.target.value)} value={url} className="form-control" type="text" id="remoteurl" /> -
diff --git a/libs/remix-ui/git/src/lib/gitactions.ts b/libs/remix-ui/git/src/lib/gitactions.ts index 8ae2202082..e74d3d9bc1 100644 --- a/libs/remix-ui/git/src/lib/gitactions.ts +++ b/libs/remix-ui/git/src/lib/gitactions.ts @@ -1,7 +1,7 @@ import { ViewPlugin } from "@remixproject/engine-web"; import { ReadBlobResult, ReadCommitResult } from "isomorphic-git"; import React from "react"; -import { fileStatus, fileStatusMerge, setRemoteBranchCommits, 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 } from '../types'; import { removeSlash } from "../utils"; import { disableCallBacks, enableCallBacks } from "./listeners"; @@ -381,7 +381,7 @@ export const fetch = async (remote?: string, ref?: string, remoteRef?: string, d await plugin.call('notification', 'toast', `Fetching ${remote || ''} ${ref || ''} ${remoteRef || ''}`) try { await plugin.call('dGitProvider' as any, 'fetch', { remote, ref, remoteRef, depth, singleBranch, relative }); - if(!quiet){ + if (!quiet) { await gitlog() await getBranches() } @@ -428,6 +428,7 @@ const tokenWarning = async () => { const parseError = async (e: any) => { + console.log(e) // if message conttains 401 Unauthorized, show token warning if (e.message.includes('401')) { const result = await plugin.call('notification', 'modal', { @@ -458,6 +459,13 @@ const parseError = async (e: any) => { cancelLabel: 'Close', type: ModalTypes.confirm }) + } else if (e.toString().includes('NotFoundError') && !e.toString().includes('fetch')) { + await plugin.call('notification', 'modal', { + 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.', + okLabel: 'OK', + type: ModalTypes.alert + }) } else { await plugin.call('notification', 'alert', { title: 'Error', @@ -475,12 +483,12 @@ export const repositories = async () => { let page = 2 let hasMoreData = true const per_page = 100 - while(hasMoreData){ - let pagedResponse = await plugin.call('dGitProvider' as any, 'repositories', { token, page:page, per_page: per_page }) - if(pagedResponse.length < per_page){ + while (hasMoreData) { + let pagedResponse = await plugin.call('dGitProvider' as any, 'repositories', { token, page: page, per_page: per_page }) + if (pagedResponse.length < per_page) { hasMoreData = false } - repos = [...repos,...pagedResponse] + repos = [...repos, ...pagedResponse] dispatch(setRepos(repos)) page++ } @@ -511,12 +519,12 @@ export const remoteBranches = async (owner: string, repo: string) => { let page = 2 let hasMoreData = true const per_page = 100 - while(hasMoreData){ - let pagedResponse = await plugin.call('dGitProvider' as any, 'remotebranches', { token, owner, repo, page:page, per_page: per_page }) - if(pagedResponse.length < per_page){ + while (hasMoreData) { + let pagedResponse = await plugin.call('dGitProvider' as any, 'remotebranches', { token, owner, repo, page: page, per_page: per_page }) + if (pagedResponse.length < per_page) { hasMoreData = false } - branches = [...branches,...pagedResponse] + branches = [...branches, ...pagedResponse] dispatch(setRemoteBranches(branches)) page++ } @@ -736,11 +744,22 @@ export const diff = async (commitChange: commitChange) => { export const getCommitChanges = async (oid1: string, oid2: string, branch?: branch, remote?: remote) => { console.log(oid1, oid2, branch, remote) - try{ + + try { + // check if oid2 exists + const log = await plugin.call('dGitProvider', 'log', { + ref: branch? branch.name : 'HEAD', + }) + if(log) { + const foundCommit = log.find((commit: ReadCommitResult) => commit.oid === oid2) + if(!foundCommit) { + await fetch(remote? remote.remote: null, branch? branch.name: null,null, 5, true, true) + } + } const result: commitChange[] = await plugin.call('dGitProvider', 'getCommitChanges', oid1, oid2) dispatch(setCommitChanges(result)) return result - }catch(e){ + } catch (e) { console.log(e) return false } @@ -759,9 +778,12 @@ async function getRepoDetails(url: string) { export const fetchBranch = async (branch: branch, page: number) => { - if(!branch.remote || !branch.remote.url) return + if (!branch.remote || !branch.remote.url) return const token = await tokenWarning(); console.log('fetch', branch) + if (page == 1) { + dispatch(resetRemoteBranchCommits({ branch })) + } 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 }); console.log(rc, 'remote commits from octokit') @@ -825,28 +847,31 @@ export const getBranchCommits = async (branch: branch, page: number) => { const commits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', { ref: branch.name, }) - - const branchDifference: branchDifference = await plugin.call('dGitProvider', 'compareBranches', { - branch, - remote: { - remote: 'origin', - url: '' - } - }) - console.log(commits, branchDifference) - dispatch(setBranchDifferences( - { + try { + const branchDifference: branchDifference = await plugin.call('dGitProvider', 'compareBranches', { branch, - remote: - { remote: 'origin', url: '' }, + remote: { + remote: 'origin', + url: '' + } + }) + console.log(commits, branchDifference) + dispatch(setBranchDifferences( + { + branch, + remote: + { remote: 'origin', url: '' }, branchDifference: branchDifference - })) + })) + } catch (e) { + + } dispatch(setLocalBranchCommits({ branch, commits })) } else { await fetchBranch(branch, page) } } catch (e) { - console.log(e) + console.trace(e) await fetchBranch(branch, page) } dispatch(setLoading(false)) diff --git a/libs/remix-ui/git/src/lib/listeners.ts b/libs/remix-ui/git/src/lib/listeners.ts index f176588828..bbac95901a 100644 --- a/libs/remix-ui/git/src/lib/listeners.ts +++ b/libs/remix-ui/git/src/lib/listeners.ts @@ -196,7 +196,7 @@ export const enableCallBacks = async () => { } const synTimerStart = async () => { - console.trace('synTimerStart') + //console.trace('synTimerStart') if (!callBackEnabled) return clearTimeout(syncTimer) syncTimer = setTimeout(async () => { diff --git a/libs/remix-ui/git/src/state/gitpayload.ts b/libs/remix-ui/git/src/state/gitpayload.ts index aef51b2574..6c3897107d 100644 --- a/libs/remix-ui/git/src/state/gitpayload.ts +++ b/libs/remix-ui/git/src/state/gitpayload.ts @@ -142,6 +142,18 @@ export const setRemoteBranchCommits = ({ branch, commits }:{ } } +export const resetRemoteBranchCommits = ({ branch }:{ + branch: branch, +}):{ + type: string; + payload: { branch: branch }; +} => { + return { + type: 'RESET_REMOTE_BRANCH_COMMITS', + payload: { branch } + } +} + export const setLocalBranchCommits = ({ branch, commits diff --git a/libs/remix-ui/git/src/state/gitreducer.tsx b/libs/remix-ui/git/src/state/gitreducer.tsx index d344a6c4ca..ac37bfe4b2 100644 --- a/libs/remix-ui/git/src/state/gitreducer.tsx +++ b/libs/remix-ui/git/src/state/gitreducer.tsx @@ -119,6 +119,15 @@ export const gitReducer = (state: gitState = defaultGitState, action: Action): g commitChanges: [...state.commitChanges] } + case 'RESET_REMOTE_BRANCH_COMMITS': + if (state.remoteBranchCommits[(action as setRemoteBranchCommitsAction).payload.branch.name]) { + delete state.remoteBranchCommits[(action as setRemoteBranchCommitsAction).payload.branch.name] + } + return { + ...state, + remoteBranchCommits: { ...state.remoteBranchCommits } + } + case 'SET_REMOTE_BRANCH_COMMITS': if (state.remoteBranchCommits[(action as setRemoteBranchCommitsAction).payload.branch.name]) { state.remoteBranchCommits[(action as setRemoteBranchCommitsAction).payload.branch.name].push(...(action as setRemoteBranchCommitsAction).payload.commits)