fix checkout

desktop-master-git2
bunsenstraat 3 months ago
parent a17d5470b9
commit 847d927649
  1. 112
      apps/remixdesktop/src/plugins/isoGitPlugin.ts
  2. 7
      apps/remixdesktop/src/tools/git.ts
  3. 2
      libs/remix-ui/git/src/components/panels/branches/remotebranchedetails.tsx

@ -1,11 +1,11 @@
import { Profile } from "@remixproject/plugin-utils"; import {Profile} from '@remixproject/plugin-utils'
import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron" import {ElectronBasePlugin, ElectronBasePluginClient} from '@remixproject/plugin-electron'
import fs from 'fs/promises' import fs from 'fs/promises'
import git from 'isomorphic-git' import git from 'isomorphic-git'
import http from 'isomorphic-git/http/web' import http from 'isomorphic-git/http/web'
import { gitProxy } from "../tools/git"; import {gitProxy} from '../tools/git'
import { isoGit } from "@remix-git" import {isoGit} from '@remix-git'
import { branchDifference, branchInputType, cloneInputType, commitChange, commitInputType, compareBranchesInput, currentBranchInput, fetchInputType, initInputType, logInputType, pullInputType, pushInputType, remote, resolveRefInput, statusInput } from "@remix-api"; import {branchDifference, branchInputType, checkoutInputType, cloneInputType, commitChange, commitInputType, compareBranchesInput, currentBranchInput, fetchInputType, initInputType, logInputType, pullInputType, pushInputType, remote, resolveRefInput, statusInput} from '@remix-api'
const profile: Profile = { const profile: Profile = {
name: 'isogit', name: 'isogit',
@ -13,7 +13,7 @@ const profile: Profile = {
description: 'isogit plugin', description: 'isogit plugin',
} }
// used in e2e tests // used in e2e tests
const useIsoGit = process.argv.includes('--use-isogit'); const useIsoGit = process.argv.includes('--use-isogit')
export class IsoGitPlugin extends ElectronBasePlugin { export class IsoGitPlugin extends ElectronBasePlugin {
clients: IsoGitPluginClient[] = [] clients: IsoGitPluginClient[] = []
constructor() { constructor() {
@ -21,19 +21,18 @@ export class IsoGitPlugin extends ElectronBasePlugin {
} }
startClone(webContentsId: any): void { startClone(webContentsId: any): void {
const client = this.clients.find(c => c.webContentsId === webContentsId) const client = this.clients.find((c) => c.webContentsId === webContentsId)
if (client) { if (client) {
client.startClone() client.startClone()
} }
} }
} }
const clientProfile: Profile = { const clientProfile: Profile = {
name: 'isogit', name: 'isogit',
displayName: 'isogit', displayName: 'isogit',
description: 'isogit plugin', description: 'isogit plugin',
methods: ['init', 'localStorageUsed', 'version', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'export', 'import', 'status', 'log', 'commit', 'add', 'remove', 'rm', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pin', 'pull', 'pinList', 'unPin', 'setIpfsConfig', 'zip', 'setItem', 'getItem', 'openFolder', 'getCommitChanges', 'compareBranches', 'startClone', 'updateSubmodules'] methods: ['init', 'localStorageUsed', 'version', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'export', 'import', 'status', 'log', 'commit', 'add', 'remove', 'rm', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pin', 'pull', 'pinList', 'unPin', 'setIpfsConfig', 'zip', 'setItem', 'getItem', 'openFolder', 'getCommitChanges', 'compareBranches', 'startClone', 'updateSubmodules'],
} }
class IsoGitPluginClient extends ElectronBasePluginClient { class IsoGitPluginClient extends ElectronBasePluginClient {
@ -44,15 +43,15 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
this.onload(async () => { this.onload(async () => {
this.on('fs' as any, 'workingDirChanged', async (path: string) => { this.on('fs' as any, 'workingDirChanged', async (path: string) => {
this.workingDir = path this.workingDir = path
this.gitIsInstalled = await gitProxy.version() && !useIsoGit ? true : false this.gitIsInstalled = (await gitProxy.version()) && !useIsoGit ? true : false
}) })
this.workingDir = await this.call('fs' as any, 'getWorkingDir') this.workingDir = await this.call('fs' as any, 'getWorkingDir')
this.gitIsInstalled = await gitProxy.version() && !useIsoGit ? true : false this.gitIsInstalled = (await gitProxy.version()) && !useIsoGit ? true : false
}) })
} }
async version() { async version() {
return this.gitIsInstalled? gitProxy.version(): 'built-in' return this.gitIsInstalled ? gitProxy.version() : 'built-in'
} }
async getGitConfig() { async getGitConfig() {
@ -68,7 +67,6 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
throw new Error('No working directory') throw new Error('No working directory')
} }
if (this.workingDir === '') { if (this.workingDir === '') {
return [] return []
} }
@ -79,8 +77,8 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
} }
const status = await git.statusMatrix({ const status = await git.statusMatrix({
...await this.getGitConfig(), ...(await this.getGitConfig()),
...cmd ...cmd,
}) })
//console.log('STATUS', status, await this.getGitConfig()) //console.log('STATUS', status, await this.getGitConfig())
return status return status
@ -90,15 +88,15 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
console.log('LOG', cmd) console.log('LOG', cmd)
const token = await this.call('config' as any, 'getAppParameter', 'settings/gist-access-token') const token = await this.call('config' as any, 'getAppParameter', 'settings/gist-access-token')
console.log('LOG', token) console.log('LOG', token)
if (this.workingDir === '') { if (this.workingDir === '') {
return [] return []
} }
const log = await git.log({ const log = await git.log({
...await this.getGitConfig(), ...(await this.getGitConfig()),
...cmd, ...cmd,
depth: cmd.depth || 10 depth: cmd.depth || 10,
}) })
console.log('LOG') console.log('LOG')
return log return log
@ -110,22 +108,21 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
} }
const add = await git.add({ const add = await git.add({
...await this.getGitConfig(), ...(await this.getGitConfig()),
...cmd ...cmd,
}) })
return add return add
} }
async rm(cmd: any) { async rm(cmd: any) {
if (!this.workingDir || this.workingDir === '') { if (!this.workingDir || this.workingDir === '') {
throw new Error('No working directory') throw new Error('No working directory')
} }
const rm = await git.remove({ const rm = await git.remove({
...await this.getGitConfig(), ...(await this.getGitConfig()),
...cmd ...cmd,
}) })
return rm return rm
@ -142,15 +139,14 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
} }
const commit = await git.commit({ const commit = await git.commit({
...await this.getGitConfig(), ...(await this.getGitConfig()),
...cmd ...cmd,
}) })
return commit return commit
} }
async init(input: initInputType) { async init(input: initInputType) {
if (!this.workingDir || this.workingDir === '') { if (!this.workingDir || this.workingDir === '') {
throw new Error('No working directory') throw new Error('No working directory')
} }
@ -159,8 +155,8 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
return status return status
} }
await git.init({ await git.init({
...await this.getGitConfig(), ...(await this.getGitConfig()),
defaultBranch: (input && input.defaultBranch) || 'main' defaultBranch: (input && input.defaultBranch) || 'main',
}) })
} }
@ -169,8 +165,8 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
return null return null
} }
const branch = await git.branch({ const branch = await git.branch({
...await this.getGitConfig(), ...(await this.getGitConfig()),
...cmd ...cmd,
}) })
return branch return branch
@ -183,40 +179,41 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
} }
const resolveref = await git.resolveRef({ const resolveref = await git.resolveRef({
...await this.getGitConfig(), ...(await this.getGitConfig()),
...cmd ...cmd,
}) })
console.log('RESOLVE REF', resolveref) console.log('RESOLVE REF', resolveref)
return resolveref return resolveref
} }
async readblob(cmd: any) { async readblob(cmd: any) {
if (!this.workingDir || this.workingDir === '') { if (!this.workingDir || this.workingDir === '') {
throw new Error('No working directory') throw new Error('No working directory')
} }
const readblob = await git.readBlob({ const readblob = await git.readBlob({
...await this.getGitConfig(), ...(await this.getGitConfig()),
...cmd ...cmd,
}) })
return readblob return readblob
} }
async checkout(cmd: any) { async checkout(cmd: checkoutInputType) {
console.log('CHECKOUT', cmd)
if (!this.workingDir || this.workingDir === '') { if (!this.workingDir || this.workingDir === '') {
throw new Error('No working directory') throw new Error('No working directory')
} }
if (this.gitIsInstalled) {
const checkout = await git.checkout({ return await gitProxy.checkout(this.workingDir, cmd)
...await this.getGitConfig(), } else {
...cmd const checkout = await git.checkout({
}) ...(await this.getGitConfig()),
...cmd,
return checkout })
return checkout
}
} }
async push(input: pushInputType) { async push(input: pushInputType) {
@ -231,7 +228,6 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
const push = await isoGit.push(input, await this.getGitConfig(), this) const push = await isoGit.push(input, await this.getGitConfig(), this)
return push return push
} }
} }
async pull(input: pullInputType) { async pull(input: pullInputType) {
@ -256,7 +252,6 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
if (this.gitIsInstalled) { if (this.gitIsInstalled) {
await gitProxy.fetch(this.workingDir, input) await gitProxy.fetch(this.workingDir, input)
} else { } else {
const fetch = await isoGit.fetch(input, await this.getGitConfig(), this) const fetch = await isoGit.fetch(input, await this.getGitConfig(), this)
return fetch return fetch
@ -264,7 +259,6 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
} }
async clone(cmd: cloneInputType) { async clone(cmd: cloneInputType) {
if (this.gitIsInstalled) { if (this.gitIsInstalled) {
try { try {
this.call('terminal' as any, 'log', 'Cloning using git... please wait.') this.call('terminal' as any, 'log', 'Cloning using git... please wait.')
@ -285,27 +279,24 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
} }
async addremote(input: remote) { async addremote(input: remote) {
const addremote = await git.addRemote({ const addremote = await git.addRemote({
...await this.getGitConfig(), ...(await this.getGitConfig()),
url: input.url, remote: input.name url: input.url,
remote: input.name,
}) })
return addremote return addremote
} }
async delremote(input: remote) { async delremote(input: remote) {
const delremote = await git.deleteRemote({ const delremote = await git.deleteRemote({
...await this.getGitConfig(), ...(await this.getGitConfig()),
remote: input.name remote: input.name,
}) })
return delremote return delremote
} }
async remotes() { async remotes() {
console.log('REMOTES') console.log('REMOTES')
if (!this.workingDir || this.workingDir === '') { if (!this.workingDir || this.workingDir === '') {
@ -324,7 +315,6 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
return await isoGit.currentbranch(input, defaultConfig) return await isoGit.currentbranch(input, defaultConfig)
} }
async branches(config: any) { async branches(config: any) {
console.log('BRANCHES') console.log('BRANCHES')
if (!this.workingDir || this.workingDir === '') { if (!this.workingDir || this.workingDir === '') {
@ -335,7 +325,6 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
return await isoGit.branches(defaultConfig) return await isoGit.branches(defaultConfig)
} }
async startClone() { async startClone() {
this.call('filePanel' as any, 'clone') this.call('filePanel' as any, 'clone')
} }
@ -344,8 +333,8 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
return await isoGit.getCommitChanges(commitHash1, commitHash2, await this.getGitConfig()) return await isoGit.getCommitChanges(commitHash1, commitHash2, await this.getGitConfig())
} }
async compareBranches({ branch, remote }: compareBranchesInput): Promise<branchDifference> { async compareBranches({branch, remote}: compareBranchesInput): Promise<branchDifference> {
return await isoGit.compareBranches({ branch, remote }, await this.getGitConfig()) return await isoGit.compareBranches({branch, remote}, await this.getGitConfig())
} }
async updateSubmodules(input) { async updateSubmodules(input) {
@ -356,10 +345,7 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
throw e throw e
} }
} else { } else {
this.call('terminal', 'log', { type: 'error', value: 'Please install git into your OS to use this functionality...' }) this.call('terminal', 'log', {type: 'error', value: 'Please install git into your OS to use this functionality...'})
} }
} }
} }

@ -1,7 +1,7 @@
import { exec } from 'child_process'; import { exec } from 'child_process';
import { CommitObject, ReadCommitResult } from 'isomorphic-git'; import { CommitObject, ReadCommitResult } from 'isomorphic-git';
import { promisify } from 'util'; import { promisify } from 'util';
import { cloneInputType, commitInputType, fetchInputType, pullInputType, pushInputType } from "@remix-api"; import { cloneInputType, commitInputType, fetchInputType, pullInputType, pushInputType, checkoutInputType } from "@remix-api";
const execAsync = promisify(exec); const execAsync = promisify(exec);
const statusTransFormMatrix = (status: string) => { const statusTransFormMatrix = (status: string) => {
@ -97,6 +97,11 @@ export const gitProxy = {
} }
}, },
async checkout(path: string, input: checkoutInputType) {
let force = input.force ? ' -f' : '';
const { stdout, stderr } = await execAsync(`git checkout ${force} ${input.ref}`, { cwd: path });
},
async commit(path: string, input: commitInputType) { async commit(path: string, input: commitInputType) {
await execAsync(`git commit -m '${input.message}'`, { cwd: path }); await execAsync(`git commit -m '${input.message}'`, { cwd: path });

@ -60,7 +60,7 @@ export const RemoteBranchDetails = (props: BrancheDetailsProps) => {
}) })
await actions.checkout({ await actions.checkout({
ref: branch.name, ref: branch.name,
remote: branch.remote && branch.remote.name || null, //remote: branch.remote && branch.remote.name || null,
refresh: true refresh: true
}); });
await actions.getBranches() await actions.getBranches()

Loading…
Cancel
Save