fetch branches

pull/2879/head
David Disu 2 years ago
parent a70b09d53f
commit 9f0edcbb7d
  1. 16
      apps/remix-ide/src/app/files/dgitProvider.js
  2. 5
      libs/remix-ui/helper/src/lib/remix-ui-helper.ts
  3. 2
      libs/remix-ui/workspace/src/lib/actions/payload.ts
  4. 82
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  5. 17
      libs/remix-ui/workspace/src/lib/reducers/workspace.ts
  6. 2
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -9,6 +9,7 @@ import {
saveAs
} from 'file-saver'
import http from 'isomorphic-git/http/web'
import { IndexedDBStorage } from './filesystems/indexedDB'
const JSZip = require('jszip')
const path = require('path')
@ -145,17 +146,16 @@ class DGitProvider extends Plugin {
return status
}
async currentbranch () {
const name = await git.currentBranch({
...await this.getGitConfig()
})
async currentbranch (config) {
console.log('config: ', config)
const cmd = config ? config : await this.getGitConfig()
const name = await git.currentBranch(cmd)
return name
}
async branches () {
const cmd = {
...await this.getGitConfig()
}
async branches (config) {
const cmd = config ? config : await this.getGitConfig()
const remotes = await this.remotes()
let branches = []
branches = (await git.listBranches(cmd)).map((branch) => { return { remote: undefined, name: branch } })

@ -123,3 +123,8 @@ export const shortenHexData = (data) => {
const len = data.length
return data.slice(0, 5) + '...' + data.slice(len - 5, len)
}
export const addSlash = (file: string) => {
if (!file.startsWith('/'))file = '/' + file
return file
}

@ -126,7 +126,7 @@ export const createWorkspaceRequest = (promise: Promise<any>) => {
}
}
export const createWorkspaceSuccess = (workspaceName: { name: string; isGitRepo: boolean; }) => {
export const createWorkspaceSuccess = (workspaceName: { name: string; isGitRepo: boolean; branches?: { remote: any; name: string; }[], currentBranch?: string }) => {
return {
type: 'CREATE_WORKSPACE_SUCCESS',
payload: workspaceName

@ -2,12 +2,18 @@ import React from 'react'
import { bufferToHex, keccakFromString } from 'ethereumjs-util'
import axios, { AxiosResponse } from 'axios'
import { addInputFieldSuccess, cloneRepositoryFailed, cloneRepositoryRequest, cloneRepositorySuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, displayPopUp, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload'
import { checkSlash, checkSpecialChars } from '@remix-ui/helper'
import { addSlash, checkSlash, checkSpecialChars } from '@remix-ui/helper'
import { JSONStandardInput, WorkspaceTemplate } from '../types'
import { QueryParams } from '@remix-project/remix-lib'
import * as templateWithContent from '@remix-project/remix-ws-templates'
import { ROOT_PATH } from '../utils/constants'
// eslint-disable-next-line @nrwl/nx/enforce-module-boundaries
import { IndexedDBStorage } from '../../../../../../apps/remix-ide/src/app/files/filesystems/indexedDB'
declare global {
interface Window { remixFileSystemCallback: IndexedDBStorage; }
}
const LOCALHOST = ' - connect to localhost - '
@ -48,6 +54,25 @@ export const createWorkspace = async (workspaceName: string, workspaceTemplateNa
const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName)
dispatch(createWorkspaceRequest(promise))
promise.then(async () => {
if (isGitRepo) {
let branches = []
let currentBranch = null
try {
branches = await getGitRepoBranches(`${plugin.fileProviders.workspace.workspacesPath}/${workspaceName}`)
} catch (e) {
console.error(e)
}
try {
currentBranch = await getGitRepoCurrentBranch(`${plugin.fileProviders.workspace.workspacesPath}/${workspaceName}`)
} catch (e) {
console.error(e)
}
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo, branches, currentBranch }))
} else {
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo }))
}
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo }))
await plugin.setWorkspace({ name: workspaceName, isLocalhost: false })
await plugin.setWorkspaces(await getWorkspaces())
@ -263,7 +288,7 @@ export const switchToWorkspace = async (name: string) => {
if (isActive) await plugin.call('manager', 'deactivatePlugin', 'remixd')
await plugin.fileProviders.workspace.setWorkspace(name)
await plugin.setWorkspace({ name, isLocalhost: false })
const isGitRepo = await plugin.fileManager.isGitRepo()
const isGitRepo = await plugin.fileManager.isGitRepo(name)
dispatch(setMode('browser'))
dispatch(setCurrentWorkspace({ name, isGitRepo }))
@ -325,10 +350,37 @@ export const getWorkspaces = async (): Promise<{name: string, isGitRepo: boolean
Promise.all(Object.keys(items)
.filter((item) => items[item].isDirectory)
.map(async (folder) => {
console.log('folder: ', folder)
const isGitRepo: boolean = await plugin.fileProviders.browser.exists('/' + folder + '/.git')
return {
name: folder.replace(workspacesPath + '/', ''),
isGitRepo
if (isGitRepo) {
let branches = []
let currentBranch = null
try {
branches = await getGitRepoBranches(folder)
} catch (e) {
console.error(e)
}
try {
currentBranch = await getGitRepoCurrentBranch(folder)
} catch (e) {
console.error(e)
}
console.log('branches: ', branches)
return {
name: folder.replace(workspacesPath + '/', ''),
isGitRepo,
branches,
currentBranch
}
} else {
return {
name: folder.replace(workspacesPath + '/', ''),
isGitRepo
}
}
})).then(workspacesList => resolve(workspacesList))
})
@ -397,3 +449,23 @@ export const getRepositoryTitle = async (url: string) => {
return name + counter
}
export const getGitRepoBranches = async (workspacePath: string) => {
const gitConfig: { fs: IndexedDBStorage, dir: string } = {
fs: window.remixFileSystemCallback,
dir: addSlash(workspacePath)
}
const branches: { remote: any; name: string; }[] = await plugin.call('dGitProvider', 'branches', gitConfig)
return branches
}
export const getGitRepoCurrentBranch = async (workspaceName: string) => {
const gitConfig: { fs: IndexedDBStorage, dir: string } = {
fs: window.remixFileSystemCallback,
dir: addSlash(workspaceName)
}
const currentBranch: string = await plugin.call('dGitProvider', 'currentbranch', gitConfig)
return currentBranch
}

@ -13,6 +13,11 @@ export interface BrowserState {
workspaces: {
name: string;
isGitRepo: boolean;
branches?: {
remote: any;
name: string;
}[],
currentBranch?: string
}[],
files: { [x: string]: Record<string, FileType> },
expandPath: string[]
@ -117,7 +122,7 @@ export const browserInitialState: BrowserState = {
export const browserReducer = (state = browserInitialState, action: Action) => {
switch (action.type) {
case 'SET_CURRENT_WORKSPACE': {
const payload = action.payload as { name: string; isGitRepo: boolean; }
const payload = action.payload as { name: string; isGitRepo: boolean; branches?: { remote: any; name: string; }[], currentBranch?: string }
const workspaces = state.browser.workspaces.find(({ name }) => name === payload.name) ? state.browser.workspaces : [...state.browser.workspaces, action.payload]
return {
@ -131,7 +136,7 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
}
case 'SET_WORKSPACES': {
const payload = action.payload as { name: string; isGitRepo: boolean; }[]
const payload = action.payload as { name: string; isGitRepo: boolean; branches?: { remote: any; name: string; }[], currentBranch?: string }[]
return {
...state,
@ -429,7 +434,7 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
}
case 'CREATE_WORKSPACE_SUCCESS': {
const payload = action.payload as { name: string; isGitRepo: boolean; }
const payload = action.payload as { name: string; isGitRepo: boolean; branches?: { remote: any; name: string; }[], currentBranch?: string }
const workspaces = state.browser.workspaces.find(({ name }) => name === payload.name) ? state.browser.workspaces : [...state.browser.workspaces, action.payload]
return {
@ -460,13 +465,15 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
case 'RENAME_WORKSPACE': {
const payload = action.payload as { oldName: string, workspaceName: string }
let renamedWorkspace
const workspaces = state.browser.workspaces.filter(({ name, isGitRepo }) => {
const workspaces = state.browser.workspaces.filter(({ name, isGitRepo, branches, currentBranch }) => {
if (name && (name !== payload.oldName)) {
return true
} else {
renamedWorkspace = {
name: payload.workspaceName,
isGitRepo
isGitRepo,
branches,
currentBranch
}
return false
}

@ -679,7 +679,7 @@ export function Workspace () {
</div>
</div>
</div>
<div className='bg-light border-top' style={{ height: '5%' }}>
<div className={`bg-light border-top ${selectedWorkspace && selectedWorkspace.isGitRepo ? 'd-block' : 'd-none'}`} style={{ height: '5%' }}>
<div className='d-flex justify-space-between p-1'>
<div className="mr-auto text-uppercase text-dark pt-2 pl-2">DGIT</div>
<div className="pt-1 mr-1">

Loading…
Cancel
Save