From 77305321d6945b03226e80602a745fc27a2a9a18 Mon Sep 17 00:00:00 2001 From: David Disu Date: Tue, 13 Sep 2022 15:30:26 +0100 Subject: [PATCH] separate local branch from remote branch --- .../workspace/src/lib/actions/workspace.ts | 20 ++++++++++++++++--- .../workspace/src/lib/remix-ui-workspace.tsx | 19 ++++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index ecced67abe..898a73d046 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -480,13 +480,27 @@ export const switchToNewBranch = async (branch: string) => { promise.then(async () => { await fetchWorkspaceDirectory(ROOT_PATH) dispatch(setCurrentWorkspaceCurrentBranch(branch)) - const workspacesPath = plugin.fileProviders.workspace.workspacesPath - const branches = await getGitRepoBranches(workspacesPath + '/' + branch) + // const workspacesPath = plugin.fileProviders.workspace.workspacesPath + // const branches = await getGitRepoBranches(workspacesPath + '/' + branch) - dispatch(setCurrentWorkspaceBranches(branches)) + // dispatch(setCurrentWorkspaceBranches(branches)) dispatch(cloneRepositorySuccess()) }).catch(() => { dispatch(cloneRepositoryFailed()) }) return promise } + +export const hasLocalChanges = async (branch: string) => { + const staged = await plugin.call('dGitProvider', 'lsfiles', { ref: branch }) + const untracked = await plugin.call('dGitProvider', 'unstagedStatus', { ref: branch }) + const deleted = await plugin.call('dGitProvider', 'deleteStatus', { ref: branch }) + const modified = await plugin.call('dGitProvider', 'modifiedStatus', { ref: branch }) + + console.log('staged: ', staged) + console.log('untracked: ', untracked) + console.log('deleted: ', deleted) + console.log('modified: ', modified) + + return deleted.length > 0 || staged.length > 0 || untracked.length > 0 || modified.length > 0 +} 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 317b0b0bc0..b209584a72 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -30,7 +30,7 @@ export function Workspace () { const workspaceCreateTemplateInput = useRef() const cloneUrlRef = useRef() const initGitRepoRef = useRef() - const filteredBranches = selectedWorkspace ? (selectedWorkspace.branches || []).filter(branch => branch.name.includes(branchFilter) && branch.remote).slice(0, 20) : [] + const filteredBranches = selectedWorkspace ? (selectedWorkspace.branches || []).filter(branch => branch.name.includes(branchFilter) && branch.name !== 'HEAD').slice(0, 20) : [] const currentBranch = selectedWorkspace ? selectedWorkspace.currentBranch : null useEffect(() => { @@ -67,7 +67,6 @@ export function Workspace () { const workspace = global.fs.browser.workspaces.find(workspace => workspace.name === currentWorkspace) setSelectedWorkspace(workspace) - // workspace && setSelectedBranch(workspace.currentBranch) }, [currentWorkspace]) const renameCurrentWorkspace = () => { @@ -218,9 +217,13 @@ export function Workspace () { global.dispatchShowAllBranches() } - const switchToBranch = async (branch: string) => { + const switchToBranch = async (branch: { remote: any, name: string }) => { try { - await global.dispatchSwitchToBranch(branch) + if (branch.remote) { + await global.dispatchSwitchToNewBranch(branch.name) + } else { + await global.dispatchSwitchToBranch(branch.name) + } } catch (e) { global.modal('Checkout Git Branch', e.message, 'OK', () => {}) } @@ -744,11 +747,11 @@ export function Workspace () { { filteredBranches.length > 0 ? filteredBranches.map((branch, index) => { return ( - { switchToBranch(branch.name) }}> + { switchToBranch(branch) }} title={branch.remote ? 'Checkout new branch from remote branch' : 'Checkout to local branch'}> { - currentBranch === branch.name ? - ✓ { branch.name } : - { branch.name } + (currentBranch === branch.name) && !branch.remote ? + { branch.name } : + { branch.remote ? `${branch.remote}/${branch.name}` : branch.name } } )