pull/4991/head
bunsenstraat 4 months ago
parent 576896793f
commit 4d193a08bc
  1. 107
      apps/remix-ide/src/app/files/dgitProvider.ts
  2. 112
      apps/remixdesktop/src/plugins/isoGitPlugin.ts
  3. 3
      apps/remixdesktop/tsconfig.json
  4. 2
      libs/remix-git/index.ts
  5. 42
      libs/remix-git/src/index.ts
  6. 128
      libs/remix-git/src/isogit.ts
  7. 2
      libs/remix-ui/git/src/lib/gitactions.ts
  8. 3
      tsconfig.paths.json

@ -20,11 +20,12 @@ import { OctokitResponse } from '@octokit/types'
import { Endpoints } from "@octokit/types"
import { IndexedDBStorage } from './filesystems/indexedDB'
import { GitHubUser, branch, commitChange, remote, userEmails } from '@remix-ui/git'
import { checkoutInputType, statusInput, logInputType, author, pagedCommits, remoteCommitsInputType, cloneInputType, fetchInputType, pullInputType, pushInputType, currentBranchInput, branchInputType, addInputType, rmInputType, resolveRefInput, readBlobInput, repositoriesInput, commitInputType, branchDifference, compareBranchesInput, initInputType} from '@remix-api'
import { checkoutInputType, statusInput, logInputType, author, pagedCommits, remoteCommitsInputType, cloneInputType, fetchInputType, pullInputType, pushInputType, currentBranchInput, branchInputType, addInputType, rmInputType, resolveRefInput, readBlobInput, repositoriesInput, commitInputType, branchDifference, compareBranchesInput, initInputType, isoGitConfig} from '@remix-api'
import { LibraryProfile, StatusEvents } from '@remixproject/plugin-utils'
import { ITerminal } from '@remixproject/plugin-api/src/lib/terminal'
import { partial } from 'lodash'
import { CustomRemixApi } from '@remix-api'
import { isoGit } from "libs/remix-git/src/isogit"
declare global {
interface Window { remixFileSystemCallback: IndexedDBStorage; remixFileSystem: any; }
@ -334,53 +335,7 @@ class DGitProvider extends Plugin<any, CustomRemixApi> {
return result
}
const result: commitChange[] = await git.walk({
...await this.addIsomorphicGitConfigFS(),
trees: [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })],
map: async function (filepath, [A, B]) {
if (filepath === '.') {
return
}
try {
if ((A && await A.type()) === 'tree' || B && (await B.type()) === 'tree') {
return
}
} catch (e) {
// ignore
}
// generate ids
const Aoid = A && await A.oid() || undefined
const Boid = B && await B.oid() || undefined
const commitChange: Partial<commitChange> = {
hashModified: commitHash1,
hashOriginal: commitHash2,
path: filepath,
}
// determine modification type
if (Aoid !== Boid) {
commitChange.type = "modified"
}
if (Aoid === undefined) {
commitChange.type = "deleted"
}
if (Boid === undefined || !commitHash2) {
commitChange.type = "added"
}
if (Aoid === undefined && Boid === undefined) {
commitChange.type = "unknown"
}
if (commitChange.type)
return commitChange
else
return undefined
},
})
return result
return await isoGit.getCommitChanges(commitHash1, commitHash2, await this.addIsomorphicGitConfigFS())
}
async remotes(): Promise<remote[]> {
@ -388,14 +343,7 @@ class DGitProvider extends Plugin<any, CustomRemixApi> {
return await this.call('isogit', 'remotes')
}
let remotes: remote[] = []
try {
remotes = (await git.listRemotes({ ...await this.addIsomorphicGitConfigFS() })).map((remote) => { return { name: remote.remote, url: remote.url } }
)
} catch (e) {
// do nothing
}
return remotes
return await isoGit.remotes(await this.addIsomorphicGitConfigFS())
}
async branch(cmd: branchInputType): Promise<void> {
@ -424,61 +372,20 @@ class DGitProvider extends Plugin<any, CustomRemixApi> {
return await this.call('isogit', 'currentbranch', input)
}
try {
const defaultConfig = await this.addIsomorphicGitConfigFS()
const cmd = input ? defaultConfig ? { ...defaultConfig, ...input } : input : defaultConfig
const name = await git.currentBranch(cmd)
let remote: remote = undefined
try {
const remoteName = await git.getConfig({
...defaultConfig,
path: `branch.${name}.remote`
})
if (remoteName) {
const remoteUrl = await git.getConfig({
...defaultConfig,
path: `remote.${remoteName}.url`
})
remote = { name: remoteName, url: remoteUrl }
return await isoGit.currentbranch(input, defaultConfig)
}
} catch (e) {
// do nothing
}
return {
remote: remote,
name: name || ''
}
} catch (e) {
return undefined
}
}
async branches(config): Promise<branch[]> {
async branches(config: isoGitConfig): Promise<branch[]> {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
const branches = await this.call('isogit', 'branches')
console.log(branches)
return branches
}
try {
const defaultConfig = await this.addIsomorphicGitConfigFS()
const cmd = config ? defaultConfig ? { ...defaultConfig, ...config } : config : defaultConfig
const remotes = await this.remotes()
let branches: branch[] = []
branches = (await git.listBranches(cmd)).map((branch) => { return { remote: undefined, name: branch } })
for (const remote of remotes) {
cmd.remote = remote.name
const remotebranches = (await git.listBranches(cmd)).map((branch) => { return { remote: remote, name: branch } })
branches = [...branches, ...remotebranches]
}
return branches
} catch (e) {
console.log(e)
return []
}
return await isoGit.branches(cmd)
}
async commit(cmd: commitInputType): Promise<string> {

@ -351,20 +351,13 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
async remotes () {
async remotes() {
console.log('REMOTES')
if (!this.workingDir || this.workingDir === '') {
return []
}
let remotes: remote[] = []
try {
remotes = (await git.listRemotes({ ...await this.getGitConfig() })).map((remote) => { return { name: remote.remote, url: remote.url } }
)
} catch (e) {
// do nothing
}
console.log('REMOTES', remotes)
return remotes
const defaultConfig = await this.getGitConfig()
return await isoGit.remotes(defaultConfig)
}
async currentbranch(input: currentBranchInput) {
@ -372,40 +365,8 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
if (!this.workingDir || this.workingDir === '') {
return ''
}
try {
const defaultConfig = await this.getGitConfig()
console.log(isoGit)
const cmd = input ? defaultConfig ? { ...defaultConfig, ...input } : input : defaultConfig
const name = await git.currentBranch(cmd)
let remote: remote = undefined
try {
const remoteName = await git.getConfig({
...defaultConfig,
path: `branch.${name}.remote`
})
if (remoteName) {
const remoteUrl = await git.getConfig({
...defaultConfig,
path: `remote.${remoteName}.url`
})
remote = { name: remoteName, url: remoteUrl }
}
} catch (e) {
// do nothing
}
console.log('NAME', name)
console.log('REMOTE', remote)
return {
remote: remote,
name: name || ''
}
} catch (e) {
return undefined
}
return await isoGit.currentbranch(input, defaultConfig)
}
@ -414,22 +375,9 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
if (!this.workingDir || this.workingDir === '') {
return []
}
try {
const defaultConfig = await this.getGitConfig()
const cmd = config ? defaultConfig ? { ...defaultConfig, ...config } : config : defaultConfig
const remotes = await this.remotes()
let branches: branch[] = []
branches = (await git.listBranches(cmd)).map((branch) => { return { remote: undefined, name: branch } })
for (const remote of remotes) {
cmd.remote = remote.name
const remotebranches = (await git.listBranches(cmd)).map((branch) => { return { remote: remote, name: branch } })
branches = [...branches, ...remotebranches]
}
return branches
} catch (e) {
console.log(e)
return []
}
return await isoGit.branches(defaultConfig)
}
@ -438,53 +386,7 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
}
async getCommitChanges(commitHash1: string, commitHash2: string): Promise<commitChange[]> {
const result: commitChange[] = await git.walk({
...await this.getGitConfig(),
trees: [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })],
map: async function (filepath, [A, B]) {
if (filepath === '.') {
return
}
try {
if ((A && await A.type()) === 'tree' || B && (await B.type()) === 'tree') {
return
}
} catch (e) {
// ignore
}
// generate ids
const Aoid = A && await A.oid() || undefined
const Boid = B && await B.oid() || undefined
const commitChange: Partial<commitChange> = {
hashModified: commitHash1,
hashOriginal: commitHash2,
path: filepath,
}
// determine modification type
if (Aoid !== Boid) {
commitChange.type = "modified"
}
if (Aoid === undefined) {
commitChange.type = "deleted"
}
if (Boid === undefined || !commitHash2) {
commitChange.type = "added"
}
if (Aoid === undefined && Boid === undefined) {
commitChange.type = "unknown"
}
if (commitChange.type)
return commitChange
else
return undefined
},
})
return result
return await isoGit.getCommitChanges(commitHash1, commitHash2, await this.getGitConfig())
}
async compareBranches({ branch, remote }: compareBranchesInput): Promise<branchDifference> {

@ -20,7 +20,7 @@
"../../libs/remix-api/src/lib/types/git.ts"
],
"@remix-git": [
"../../libs/remix-git/src/index.ts",
"../../libs/remix-git/"
],
},
"typeRoots": [
@ -32,6 +32,5 @@
},
"include": [
"src/**/*",
"../../libs/remix-git/src/index.ts"
]
}

@ -1 +1 @@
export * from './src/index'
export { isoGit } from './src/isogit'

@ -1,42 +0,0 @@
import { currentBranchInput, isoGitConfig, remote } from "@remix-api"
import git from 'isomorphic-git'
const currentbranch = async (input: currentBranchInput, defaultConfig: isoGitConfig ) => {
console.log('CURRENT BRANCH', input)
try {
const cmd = input ? defaultConfig ? { ...defaultConfig, ...input } : input : defaultConfig
const name = await git.currentBranch(cmd)
let remote: remote = undefined
try {
const remoteName = await git.getConfig({
...defaultConfig,
path: `branch.${name}.remote`
})
if (remoteName) {
const remoteUrl = await git.getConfig({
...defaultConfig,
path: `remote.${remoteName}.url`
})
remote = { name: remoteName, url: remoteUrl }
}
} catch (e) {
// do nothing
}
console.log('NAME', name)
console.log('REMOTE', remote)
return {
remote: remote,
name: name || ''
}
} catch (e) {
return undefined
}
}
export const isoGit = {
currentbranch
}

@ -0,0 +1,128 @@
import { branch, commitChange, currentBranchInput, isoGitConfig, remote } from "@remix-api"
import git from 'isomorphic-git'
const currentbranch = async (input: currentBranchInput, defaultConfig: isoGitConfig ) => {
console.log('CURRENT BRANCH', input)
try {
const cmd = input ? defaultConfig ? { ...defaultConfig, ...input } : input : defaultConfig
const name = await git.currentBranch(cmd)
let remote: remote = undefined
try {
const remoteName = await git.getConfig({
...defaultConfig,
path: `branch.${name}.remote`
})
if (remoteName) {
const remoteUrl = await git.getConfig({
...defaultConfig,
path: `remote.${remoteName}.url`
})
remote = { name: remoteName, url: remoteUrl }
}
} catch (e) {
// do nothing
}
console.log('NAME', name)
console.log('REMOTE', remote)
return {
remote: remote,
name: name || ''
}
} catch (e) {
return undefined
}
}
const branches = async (defaultConfig: isoGitConfig ) => {
try {
const remotes = await isoGit.remotes(defaultConfig)
let branches: branch[] = []
branches = (await git.listBranches(defaultConfig)).map((branch) => { return { remote: undefined, name: branch } })
for (const remote of remotes) {
const cmd = {
...defaultConfig,
remote: remote.name
}
const remotebranches = (await git.listBranches(cmd)).map((branch) => { return { remote: remote, name: branch } })
branches = [...branches, ...remotebranches]
}
return branches
} catch (e) {
console.log(e)
return []
}
}
const remotes = async(defaultConfig: isoGitConfig) => {
let remotes: remote[] = []
try {
remotes = (await git.listRemotes({ ...defaultConfig })).map((remote) => { return { name: remote.remote, url: remote.url } }
)
} catch (e) {
// do nothing
}
return remotes
}
const getCommitChanges = async (commitHash1: string, commitHash2: string, defaultConfig: isoGitConfig) => {
const result: commitChange[] = await git.walk({
...defaultConfig,
trees: [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })],
map: async function (filepath, [A, B]) {
if (filepath === '.') {
return
}
try {
if ((A && await A.type()) === 'tree' || B && (await B.type()) === 'tree') {
return
}
} catch (e) {
// ignore
}
// generate ids
const Aoid = A && await A.oid() || undefined
const Boid = B && await B.oid() || undefined
const commitChange: Partial<commitChange> = {
hashModified: commitHash1,
hashOriginal: commitHash2,
path: filepath,
}
// determine modification type
if (Aoid !== Boid) {
commitChange.type = "modified"
}
if (Aoid === undefined) {
commitChange.type = "deleted"
}
if (Boid === undefined || !commitHash2) {
commitChange.type = "added"
}
if (Aoid === undefined && Boid === undefined) {
commitChange.type = "unknown"
}
if (commitChange.type)
return commitChange
else
return undefined
},
})
return result
}
export const isoGit = {
currentbranch,
remotes,
branches,
getCommitChanges
}

@ -48,7 +48,7 @@ export const init = async () => {
export const getBranches = async () => {
const branches = await plugin.call('dgitApi', "branches")
const branches = await plugin.call('dgitApi', 'branches')
dispatch(setBranches(branches));
}

@ -180,6 +180,9 @@
],
"@remix-api": [
"libs/remix-api/src/index.ts"
],
"@remix-git": [
"libs/remix-git/src/index.ts"
]
}
}

Loading…
Cancel
Save