pull/4991/head
bunsenstraat 4 months ago
parent 576896793f
commit 4d193a08bc
  1. 107
      apps/remix-ide/src/app/files/dgitProvider.ts
  2. 110
      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 { Endpoints } from "@octokit/types"
import { IndexedDBStorage } from './filesystems/indexedDB' import { IndexedDBStorage } from './filesystems/indexedDB'
import { GitHubUser, branch, commitChange, remote, userEmails } from '@remix-ui/git' 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 { LibraryProfile, StatusEvents } from '@remixproject/plugin-utils'
import { ITerminal } from '@remixproject/plugin-api/src/lib/terminal' import { ITerminal } from '@remixproject/plugin-api/src/lib/terminal'
import { partial } from 'lodash' import { partial } from 'lodash'
import { CustomRemixApi } from '@remix-api' import { CustomRemixApi } from '@remix-api'
import { isoGit } from "libs/remix-git/src/isogit"
declare global { declare global {
interface Window { remixFileSystemCallback: IndexedDBStorage; remixFileSystem: any; } interface Window { remixFileSystemCallback: IndexedDBStorage; remixFileSystem: any; }
@ -334,53 +335,7 @@ class DGitProvider extends Plugin<any, CustomRemixApi> {
return result return result
} }
const result: commitChange[] = await git.walk({ return await isoGit.getCommitChanges(commitHash1, commitHash2, await this.addIsomorphicGitConfigFS())
...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
} }
async remotes(): Promise<remote[]> { async remotes(): Promise<remote[]> {
@ -388,14 +343,7 @@ class DGitProvider extends Plugin<any, CustomRemixApi> {
return await this.call('isogit', 'remotes') return await this.call('isogit', 'remotes')
} }
let remotes: remote[] = [] return await isoGit.remotes(await this.addIsomorphicGitConfigFS())
try {
remotes = (await git.listRemotes({ ...await this.addIsomorphicGitConfigFS() })).map((remote) => { return { name: remote.remote, url: remote.url } }
)
} catch (e) {
// do nothing
}
return remotes
} }
async branch(cmd: branchInputType): Promise<void> { async branch(cmd: branchInputType): Promise<void> {
@ -424,61 +372,20 @@ class DGitProvider extends Plugin<any, CustomRemixApi> {
return await this.call('isogit', 'currentbranch', input) return await this.call('isogit', 'currentbranch', input)
} }
try {
const defaultConfig = await this.addIsomorphicGitConfigFS() const defaultConfig = await this.addIsomorphicGitConfigFS()
const cmd = input ? defaultConfig ? { ...defaultConfig, ...input } : input : defaultConfig return await isoGit.currentbranch(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) { async branches(config: isoGitConfig): Promise<branch[]> {
// do nothing
}
return {
remote: remote,
name: name || ''
}
} catch (e) {
return undefined
}
}
async branches(config): Promise<branch[]> {
if ((Registry.getInstance().get('platform').api.isDesktop())) { if ((Registry.getInstance().get('platform').api.isDesktop())) {
const branches = await this.call('isogit', 'branches') const branches = await this.call('isogit', 'branches')
console.log(branches) console.log(branches)
return branches return branches
} }
try {
const defaultConfig = await this.addIsomorphicGitConfigFS() const defaultConfig = await this.addIsomorphicGitConfigFS()
const cmd = config ? defaultConfig ? { ...defaultConfig, ...config } : config : defaultConfig const cmd = config ? defaultConfig ? { ...defaultConfig, ...config } : config : defaultConfig
const remotes = await this.remotes() return await isoGit.branches(cmd)
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 []
}
} }
async commit(cmd: commitInputType): Promise<string> { async commit(cmd: commitInputType): Promise<string> {

@ -356,15 +356,8 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
if (!this.workingDir || this.workingDir === '') { if (!this.workingDir || this.workingDir === '') {
return [] return []
} }
let remotes: remote[] = [] const defaultConfig = await this.getGitConfig()
try { return await isoGit.remotes(defaultConfig)
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
} }
async currentbranch(input: currentBranchInput) { async currentbranch(input: currentBranchInput) {
@ -372,40 +365,8 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
if (!this.workingDir || this.workingDir === '') { if (!this.workingDir || this.workingDir === '') {
return '' return ''
} }
try {
const defaultConfig = await this.getGitConfig() const defaultConfig = await this.getGitConfig()
console.log(isoGit) return await isoGit.currentbranch(input, defaultConfig)
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
}
} }
@ -414,22 +375,9 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
if (!this.workingDir || this.workingDir === '') { if (!this.workingDir || this.workingDir === '') {
return [] return []
} }
try {
const defaultConfig = await this.getGitConfig() const defaultConfig = await this.getGitConfig()
const cmd = config ? defaultConfig ? { ...defaultConfig, ...config } : config : defaultConfig return await isoGit.branches(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 []
}
} }
@ -438,53 +386,7 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
} }
async getCommitChanges(commitHash1: string, commitHash2: string): Promise<commitChange[]> { async getCommitChanges(commitHash1: string, commitHash2: string): Promise<commitChange[]> {
const result: commitChange[] = await git.walk({ return await isoGit.getCommitChanges(commitHash1, commitHash2, await this.getGitConfig())
...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
} }
async compareBranches({ branch, remote }: compareBranchesInput): Promise<branchDifference> { async compareBranches({ branch, remote }: compareBranchesInput): Promise<branchDifference> {

@ -20,7 +20,7 @@
"../../libs/remix-api/src/lib/types/git.ts" "../../libs/remix-api/src/lib/types/git.ts"
], ],
"@remix-git": [ "@remix-git": [
"../../libs/remix-git/src/index.ts", "../../libs/remix-git/"
], ],
}, },
"typeRoots": [ "typeRoots": [
@ -32,6 +32,5 @@
}, },
"include": [ "include": [
"src/**/*", "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 () => { export const getBranches = async () => {
const branches = await plugin.call('dgitApi', "branches") const branches = await plugin.call('dgitApi', 'branches')
dispatch(setBranches(branches)); dispatch(setBranches(branches));
} }

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

Loading…
Cancel
Save