git4refactor
filip mertens 6 months ago
parent 353b5670ad
commit 53eee90070
  1. 7
      apps/remix-ide/src/app/files/dgitProvider.ts
  2. 2
      libs/remix-ui/git/src/components/buttons/commitmessage.tsx
  3. 2
      libs/remix-ui/git/src/components/gitui.tsx
  4. 41
      libs/remix-ui/git/src/components/navigation/branchedetails.tsx
  5. 11
      libs/remix-ui/git/src/components/panels/branches.tsx
  6. 8
      libs/remix-ui/git/src/components/panels/branches/branchdifferencedetails.tsx
  7. 6
      libs/remix-ui/git/src/components/panels/branches/localbranchdetails.tsx
  8. 7
      libs/remix-ui/git/src/components/panels/commits.tsx
  9. 5
      libs/remix-ui/git/src/lib/gitactions.ts

@ -300,14 +300,14 @@ class DGitProvider extends Plugin {
} }
async getCommitChanges(commitHash1, commitHash2): Promise<commitChange[]> { async getCommitChanges(commitHash1, commitHash2): Promise<commitChange[]> {
console.log(commitHash1, commitHash2, [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })]) //console.log(commitHash1, commitHash2, [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })])
const result: commitChange[] = await git.walk({ const result: commitChange[] = await git.walk({
...await this.addIsomorphicGitConfigFS(), ...await this.addIsomorphicGitConfigFS(),
trees: [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })], trees: [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })],
map: async function (filepath, [A, B]) { map: async function (filepath, [A, B]) {
// ignore directories // ignore directories
console.log(filepath, A, B) //console.log(filepath, A, B)
if (filepath === '.') { if (filepath === '.') {
return return
@ -330,7 +330,7 @@ class DGitProvider extends Plugin {
path: filepath, path: filepath,
} }
console.log('Aoid', Aoid, 'Boid', Boid, commitChange) //console.log('Aoid', Aoid, 'Boid', Boid, commitChange)
// determine modification type // determine modification type
if (Aoid !== Boid) { if (Aoid !== Boid) {
@ -802,6 +802,7 @@ class DGitProvider extends Plugin {
relative: input.relative, relative: input.relative,
input input
} }
console.log('fetch input', cmd)
let result let result
if ((Registry.getInstance().get('platform').api.isDesktop())) { if ((Registry.getInstance().get('platform').api.isDesktop())) {
result = await this.call('isogit', 'fetch', cmd) result = await this.call('isogit', 'fetch', cmd)

@ -76,7 +76,7 @@ export const CommitMessage = () => {
const publishEnabled = () => { const publishEnabled = () => {
const remoteEquivalentBranch = context.branches.find((b) => b.name === context.currentBranch.name && b.remote) const remoteEquivalentBranch = context.branches.find((b) => b.name === context.currentBranch.name && b.remote)
return remoteEquivalentBranch === undefined return remoteEquivalentBranch === undefined && getRemote()!== null
} }
const publishBranch = async () => { const publishBranch = async () => {

@ -159,7 +159,7 @@ export const GitUI = (props: IGitUi) => {
<BranchesNavigation eventKey="2" activePanel={activePanel} callback={setActivePanel} /> <BranchesNavigation eventKey="2" activePanel={activePanel} callback={setActivePanel} />
<Accordion.Collapse className='bg-light' eventKey="2"> <Accordion.Collapse className='bg-light' eventKey="2">
<> <>
<Branches isOpen={activePanel === '2'} /></> <Branches/></>
</Accordion.Collapse> </Accordion.Collapse>
<hr></hr> <hr></hr>
<RemotesNavigation eventKey="5" activePanel={activePanel} callback={setActivePanel} /> <RemotesNavigation eventKey="5" activePanel={activePanel} callback={setActivePanel} />

@ -3,6 +3,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import React, { useContext, useEffect } from "react"; import React, { useContext, useEffect } from "react";
import { gitActionsContext } from "../../state/context"; import { gitActionsContext } from "../../state/context";
import { branch } from "../../types"; import { branch } from "../../types";
import GitUIButton from "../buttons/gituibutton";
import { gitPluginContext } from "../gitui"; import { gitPluginContext } from "../gitui";
interface BrancheDetailsNavigationProps { interface BrancheDetailsNavigationProps {
@ -26,14 +27,28 @@ export const BrancheDetailsNavigation = (props: BrancheDetailsNavigationProps) =
} }
} }
const getRemote = () => {
return context.upstream ? context.upstream : context.defaultRemote ? context.defaultRemote : null
}
const openRemote = () => { const openRemote = () => {
window.open(`${branch.remote.url}/tree/${branch.name}`, '_blank'); const remote = branch.remote || getRemote()
window.open(`${remote.url}/tree/${branch.name}`, '_blank');
} }
const reloadBranch = () => { const reloadBranch = () => {
actions.getBranchCommits(branch, 1) actions.getBranchCommits(branch, 1)
} }
const canFetch = () => {
if (getRemote())
return context.branches.find((b) => b.name === branch.name && b.remote && b.remote.url === getRemote().url) ? true : false
}
const fetchBranch = async () => {
actions.fetch(null, branch.name, null, null, false, true)
}
return ( return (
<> <>
<div className="d-flex flex-row w-100 mb-2 mt-2"> <div className="d-flex flex-row w-100 mb-2 mt-2">
@ -46,16 +61,30 @@ export const BrancheDetailsNavigation = (props: BrancheDetailsNavigationProps) =
</div> </div>
{context.currentBranch.name === branch.name ? {context.currentBranch.name === branch.name ?
<FontAwesomeIcon className='ml-auto mr-1 pointer text-success' icon={faToggleOff} onClick={() => checkout(branch)}></FontAwesomeIcon> <GitUIButton className="btn btn-sm p-0 mr-1" onClick={() => { }}>
<FontAwesomeIcon className='pointer text-success' icon={faToggleOff} ></FontAwesomeIcon>
</GitUIButton>
: :
<FontAwesomeIcon className='ml-auto mr-1 pointer' icon={faToggleOn} onClick={() => checkout(branch)}></FontAwesomeIcon> <GitUIButton className="btn btn-sm p-0 mr-1" onClick={() => checkout(branch)}>
<FontAwesomeIcon icon={faToggleOn}></FontAwesomeIcon>
</GitUIButton>
} }
{!branch.remote && canFetch() && <>
<GitUIButton className="btn btn-sm p-0 mr-1 text-muted" onClick={() => fetchBranch()}><FontAwesomeIcon icon={faSync} ></FontAwesomeIcon></GitUIButton>
<GitUIButton className="btn btn-sm p-0 mr-1 text-muted" onClick={() => openRemote()}><FontAwesomeIcon icon={faGlobe} ></FontAwesomeIcon></GitUIButton>
</>}
{branch.remote?.url && <> {branch.remote?.url && <>
<FontAwesomeIcon className='ml-2 pointer' icon={faSync} onClick={() => reloadBranch()}></FontAwesomeIcon></>} <GitUIButton className="btn btn-sm p-0 mr-1 text-muted" onClick={() => reloadBranch()}>
<FontAwesomeIcon icon={faSync} ></FontAwesomeIcon>
</GitUIButton>
</>}
{branch.remote?.url && <> {branch.remote?.url && <>
<FontAwesomeIcon className='ml-2 pointer' icon={faGlobe} onClick={() => openRemote()}></FontAwesomeIcon></>} <GitUIButton className="btn btn-sm p-0 mr-1 text-muted" onClick={() => openRemote()}>
<FontAwesomeIcon icon={faGlobe} ></FontAwesomeIcon>
</GitUIButton>
</>}
</div> </div>
</> </>
); );

@ -7,11 +7,7 @@ import { gitPluginContext } from "../gitui";
import { LocalBranchDetails } from "./branches/localbranchdetails"; import { LocalBranchDetails } from "./branches/localbranchdetails";
import { RemoteBranchDetails } from "./branches/remotebranchedetails"; import { RemoteBranchDetails } from "./branches/remotebranchedetails";
interface BranchesProps { export const Branches = () => {
isOpen: boolean;
}
export const Branches = ({isOpen}: BranchesProps) => {
const context = React.useContext(gitPluginContext) const context = React.useContext(gitPluginContext)
const actions = React.useContext(gitActionsContext) const actions = React.useContext(gitActionsContext)
const [newBranch, setNewBranch] = useState({ value: "" }); const [newBranch, setNewBranch] = useState({ value: "" });
@ -28,11 +24,6 @@ export const Branches = ({isOpen}: BranchesProps) => {
} }
}; };
useEffect(() => {
console.log("open branches", context.branches)
//if(context.branches && context.branches.length) return
//actions.getBranches()
},[isOpen])
useEffect(() => { useEffect(() => {
console.log("branches", context.branches) console.log("branches", context.branches)

@ -5,6 +5,7 @@ import { CommitDetails } from "../commits/commitdetails";
import { CommitsNavigation } from "../../navigation/commits"; import { CommitsNavigation } from "../../navigation/commits";
import { branch, remote } from "../../../types"; import { branch, remote } from "../../../types";
import { gitActionsContext } from "../../../state/context"; import { gitActionsContext } from "../../../state/context";
import { gitPluginContext } from "../../gitui";
export interface BrancheDifferenceProps { export interface BrancheDifferenceProps {
commits: ReadCommitResult[]; commits: ReadCommitResult[];
@ -18,12 +19,17 @@ export interface BrancheDifferenceProps {
export const BranchDifferenceDetails = (props: BrancheDifferenceProps) => { export const BranchDifferenceDetails = (props: BrancheDifferenceProps) => {
const { commits, title, branch, remote, ahead, behind } = props; const { commits, title, branch, remote, ahead, behind } = props;
const [activePanel, setActivePanel] = useState<string>(""); const [activePanel, setActivePanel] = useState<string>("");
const context = React.useContext(gitPluginContext)
const actions = React.useContext(gitActionsContext) const actions = React.useContext(gitActionsContext)
if (commits.length === 0) return null if (commits.length === 0) return null
const getRemote = () => {
return remote ? remote : context.upstream ? context.upstream : context.defaultRemote ? context.defaultRemote : null
}
const getCommitChanges = async (commit: ReadCommitResult) => { const getCommitChanges = async (commit: ReadCommitResult) => {
await actions.getCommitChanges(commit.oid, commit.commit.parent[0]) await actions.getCommitChanges(commit.oid, commit.commit.parent[0], null, getRemote())
} }
return ( return (

@ -54,8 +54,12 @@ export const LocalBranchDetails = (props: BrancheDetailsProps) => {
} }
}; };
const getRemote = () => {
return context.upstream ? context.upstream : context.defaultRemote ? context.defaultRemote : null
}
const getCommitChanges = async (commit: ReadCommitResult) => { const getCommitChanges = async (commit: ReadCommitResult) => {
await actions.getCommitChanges(commit.oid, commit.commit.parent[0]) await actions.getCommitChanges(commit.oid, commit.commit.parent[0], null, getRemote())
} }
return (<Accordion activeKey={activePanel} defaultActiveKey=""> return (<Accordion activeKey={activePanel} defaultActiveKey="">

@ -29,8 +29,13 @@ export const Commits = () => {
//actions.getBranchCommits(branch, lastPageNumber+1) //actions.getBranchCommits(branch, lastPageNumber+1)
} }
const getRemote = () => {
return context.upstream ? context.upstream : context.defaultRemote ? context.defaultRemote : null
}
const getCommitChanges = async (commit: ReadCommitResult) => { const getCommitChanges = async (commit: ReadCommitResult) => {
await actions.getCommitChanges(commit.oid, commit.commit.parent[0]) await actions.getCommitChanges(commit.oid, commit.commit.parent[0],null, getRemote())
} }
const fetchIsDisabled = () => { const fetchIsDisabled = () => {

@ -710,11 +710,14 @@ export const getCommitChanges = async (oid1: string, oid2: string, branch?: bran
log = await plugin.call('dGitProvider', 'log', { log = await plugin.call('dGitProvider', 'log', {
ref: branch ? branch.name : 'HEAD', ref: branch ? branch.name : 'HEAD',
}) })
console.log(log, 'log')
} catch (e) { } catch (e) {
console.log(e, 'log error')
} }
if (log) { if (log) {
const foundCommit = log.find((commit: ReadCommitResult) => commit.oid === oid2) const foundCommit = log.find((commit: ReadCommitResult) => commit.oid === oid2)
if (!foundCommit) { if (!foundCommit && remote) {
console.log('getCommitChanges fetching remote')
await fetch(remote ? remote.remote : null, branch ? branch.name : null, null, 5, true, true) await fetch(remote ? remote.remote : null, branch ? branch.name : null, null, 5, true, true)
} }
} }

Loading…
Cancel
Save