remote refactor

git4refactor
filip mertens 7 months ago
parent 0a6c952726
commit 12c587ff57
  1. 2
      libs/remix-ui/git/src/components/buttons/commitmessage.tsx
  2. 9
      libs/remix-ui/git/src/components/buttons/sourceControlBase.tsx
  3. 2
      libs/remix-ui/git/src/components/buttons/sourcecontrolbuttons.tsx
  4. 2
      libs/remix-ui/git/src/components/navigation/branchedetails.tsx
  5. 4
      libs/remix-ui/git/src/components/navigation/remotesdetails.tsx
  6. 2
      libs/remix-ui/git/src/components/panels/branches.tsx
  7. 8
      libs/remix-ui/git/src/components/panels/branches/branchdifferences.tsx
  8. 2
      libs/remix-ui/git/src/components/panels/branches/localbranchdetails.tsx
  9. 4
      libs/remix-ui/git/src/components/panels/branches/remotebranchedetails.tsx
  10. 2
      libs/remix-ui/git/src/components/panels/commands/fetch.tsx
  11. 14
      libs/remix-ui/git/src/components/panels/commands/pushpull.tsx
  12. 4
      libs/remix-ui/git/src/components/panels/commits/commitdetails.tsx
  13. 2
      libs/remix-ui/git/src/components/panels/remotes.tsx
  14. 2
      libs/remix-ui/git/src/components/panels/remoteselect.tsx
  15. 2
      libs/remix-ui/git/src/components/panels/remotesimport.tsx
  16. 42
      libs/remix-ui/git/src/lib/gitactions.ts
  17. 2
      libs/remix-ui/git/src/state/gitreducer.tsx
  18. 4
      libs/remix-ui/git/src/types/index.ts

@ -43,7 +43,7 @@ export const CommitMessage = () => {
} }
const getRemoteName = () => { const getRemoteName = () => {
return getRemote() ? getRemote().remote : '' return getRemote() ? getRemote().name : ''
} }
const sync = async() => { const sync = async() => {

@ -34,10 +34,9 @@ export const SourceControlBase = (props: SourceControlButtonsProps) => {
useEffect(() => { useEffect(() => {
//console.log('BRANCH DIFF SourceControlButtons',branch, remote, context.branchDifferences, context.currentBranch) //console.log('BRANCH DIFF SourceControlButtons',branch, remote, context.branchDifferences, context.currentBranch)
setDefaultRemote() setDefaultRemote()
if (remote && branch && context.branchDifferences && context.branchDifferences[`${remote.remote}/${branch.name}`]) { if (remote && branch && context.branchDifferences && context.branchDifferences[`${remote.name}/${branch.name}`]) {
//console.log('BRANCH DIFF found SourceControlButtons', context.branchDifferences[`${remote.remote}/${branch.name}`]) setCommitsAhead(context.branchDifferences[`${remote.name}/${branch.name}`]?.uniqueHeadCommits)
setCommitsAhead(context.branchDifferences[`${remote.remote}/${branch.name}`]?.uniqueHeadCommits) setCommitsBehind(context.branchDifferences[`${remote.name}/${branch.name}`]?.uniqueRemoteCommits)
setCommitsBehind(context.branchDifferences[`${remote.remote}/${branch.name}`]?.uniqueRemoteCommits)
} else { } else {
setCommitsAhead([]) setCommitsAhead([])
setCommitsBehind([]) setCommitsBehind([])
@ -48,7 +47,7 @@ export const SourceControlBase = (props: SourceControlButtonsProps) => {
if (context.remotes.length > 0) { if (context.remotes.length > 0) {
// find remote called origin // find remote called origin
const origin = context.remotes.find(remote => remote.remote === 'origin') const origin = context.remotes.find(remote => remote.name === 'origin')
if (origin) { if (origin) {
setRemote(origin) setRemote(origin)
} else { } else {

@ -25,7 +25,7 @@ export const SourceControlButtons = () => {
} }
const getRemoteName = () => { const getRemoteName = () => {
return getRemote() ? getRemote().remote : '' return getRemote() ? getRemote().name : ''
} }
const pull = async () => { const pull = async () => {

@ -57,7 +57,7 @@ export const BrancheDetailsNavigation = (props: BrancheDetailsNavigationProps) =
activePanel === eventKey ? <FontAwesomeIcon className='' icon={faCaretDown}></FontAwesomeIcon> : <FontAwesomeIcon className='' icon={faCaretRight}></FontAwesomeIcon> activePanel === eventKey ? <FontAwesomeIcon className='' icon={faCaretDown}></FontAwesomeIcon> : <FontAwesomeIcon className='' icon={faCaretRight}></FontAwesomeIcon>
} }
<i className="fa fa-code-branch ml-1"></i> <i className="fa fa-code-branch ml-1"></i>
<div className={`ml-1 ${context.currentBranch.name === branch.name ? 'text-success' : ''}`}>{branch.name} {branch.remote ? `on ${branch.remote.remote}` : ''}</div> <div className={`ml-1 ${context.currentBranch.name === branch.name ? 'text-success' : ''}`}>{branch.name} {branch.remote ? `on ${branch.remote.name}` : ''}</div>
</div> </div>
{context.currentBranch.name === branch.name ? {context.currentBranch.name === branch.name ?

@ -45,7 +45,7 @@ export const RemotesDetailsNavigation = (props: RemotesDetailsNavigationProps) =
} }
<CustomTooltip tooltipText={remote.url} placement="top"> <CustomTooltip tooltipText={remote.url} placement="top">
<div className={`long-and-truncated ml-1 ${context.defaultRemote && context.defaultRemote?.url === remote.url ? 'text-success' : ''}`}> <div className={`long-and-truncated ml-1 ${context.defaultRemote && context.defaultRemote?.url === remote.url ? 'text-success' : ''}`}>
{remote.remote} <FontAwesomeIcon className='' icon={faArrowRightArrowLeft}></FontAwesomeIcon> {remote.url} {remote.name} <FontAwesomeIcon className='' icon={faArrowRightArrowLeft}></FontAwesomeIcon> {remote.url}
</div> </div>
</CustomTooltip> </CustomTooltip>
@ -56,7 +56,7 @@ export const RemotesDetailsNavigation = (props: RemotesDetailsNavigationProps) =
<GitUIButton className="btn btn-sm" onClick={setAsDefault}><FontAwesomeIcon icon={faToggleOn}></FontAwesomeIcon></GitUIButton> <GitUIButton className="btn btn-sm" onClick={setAsDefault}><FontAwesomeIcon icon={faToggleOn}></FontAwesomeIcon></GitUIButton>
} }
<GitUIButton className="btn btn-sm" onClick={async () => { <GitUIButton className="btn btn-sm" onClick={async () => {
await actions.fetch(remote.remote) await actions.fetch(remote.name)
}}><FontAwesomeIcon icon={faSync} ></FontAwesomeIcon></GitUIButton> }}><FontAwesomeIcon icon={faSync} ></FontAwesomeIcon></GitUIButton>
<GitUIButton className="btn btn-sm" onClick={() => actions.removeRemote(remote)}><FontAwesomeIcon className='text-danger' icon={faTrash} ></FontAwesomeIcon></GitUIButton> <GitUIButton className="btn btn-sm" onClick={() => actions.removeRemote(remote)}><FontAwesomeIcon className='text-danger' icon={faTrash} ></FontAwesomeIcon></GitUIButton>
{remote?.url && <GitUIButton className="btn btn-sm pr-0" onClick={() => openRemote()}><FontAwesomeIcon icon={faGlobe} ></FontAwesomeIcon></GitUIButton>} {remote?.url && <GitUIButton className="btn btn-sm pr-0" onClick={() => openRemote()}><FontAwesomeIcon icon={faGlobe} ></FontAwesomeIcon></GitUIButton>}

@ -18,7 +18,7 @@ export const Branches = () => {
const checkout = async (oid: string, remote: remote) => { const checkout = async (oid: string, remote: remote) => {
try { try {
actions.checkout({ ref: oid, remote: remote.remote }); actions.checkout({ ref: oid, remote: remote.name });
} catch (e) { } catch (e) {
// do nothing // do nothing
} }

@ -27,12 +27,12 @@ export const BranchDifferences = (props: BrancheDetailsProps) => {
const commitsAhead = (remote: remote) => { const commitsAhead = (remote: remote) => {
if(!remote) return []; if(!remote) return [];
return context.branchDifferences[`${remote.remote}/${branch.name}`]?.uniqueHeadCommits || []; return context.branchDifferences[`${remote.name}/${branch.name}`]?.uniqueHeadCommits || [];
} }
const commitsBehind = (remote: remote) => { const commitsBehind = (remote: remote) => {
if(!remote) return []; if(!remote) return [];
return context.branchDifferences[`${remote.remote}/${branch.name}`]?.uniqueRemoteCommits || []; return context.branchDifferences[`${remote.name}/${branch.name}`]?.uniqueRemoteCommits || [];
} }
if(!getRemote()) return null; if(!getRemote()) return null;
@ -40,8 +40,8 @@ export const BranchDifferences = (props: BrancheDetailsProps) => {
return ( return (
<div> <div>
<BranchDifferenceDetails ahead={true} branch={branch} remote={getRemote()} title={`ahead of ${getRemote().remote} by ${commitsAhead(getRemote()).length} commit(s)`} commits={commitsAhead(getRemote())}></BranchDifferenceDetails> <BranchDifferenceDetails ahead={true} branch={branch} remote={getRemote()} title={`ahead of ${getRemote().name} by ${commitsAhead(getRemote()).length} commit(s)`} commits={commitsAhead(getRemote())}></BranchDifferenceDetails>
<BranchDifferenceDetails behind={true} branch={branch} remote={getRemote()} title={`behind ${getRemote().remote} by ${commitsBehind(getRemote()).length} commit(s)`} commits={commitsBehind(getRemote())}></BranchDifferenceDetails> <BranchDifferenceDetails behind={true} branch={branch} remote={getRemote()} title={`behind ${getRemote().name} by ${commitsBehind(getRemote()).length} commit(s)`} commits={commitsBehind(getRemote())}></BranchDifferenceDetails>
{commitsAhead(getRemote()).length === 0 && commitsBehind(getRemote()).length === 0 ? null : <hr></hr>} {commitsAhead(getRemote()).length === 0 && commitsBehind(getRemote()).length === 0 ? null : <hr></hr>}
</div>) </div>)
} }

@ -35,7 +35,7 @@ export const LocalBranchDetails = (props: BrancheDetailsProps) => {
const checkout = (branch: branch) => { const checkout = (branch: branch) => {
actions.checkout({ actions.checkout({
ref: branch.name, ref: branch.name,
remote: branch.remote && branch.remote.remote || null remote: branch.remote && branch.remote.name || null
}); });
} }

@ -49,7 +49,7 @@ export const RemoteBranchDetails = (props: BrancheDetailsProps) => {
const checkout = async (branch: branch) => { const checkout = async (branch: branch) => {
await actions.checkout({ await actions.checkout({
ref: branch.name, ref: branch.name,
remote: branch.remote && branch.remote.remote || null remote: branch.remote && branch.remote.name || null
}); });
await actions.getBranches() await actions.getBranches()
} }
@ -74,7 +74,7 @@ export const RemoteBranchDetails = (props: BrancheDetailsProps) => {
console.log('CHANGES', changes) console.log('CHANGES', changes)
if (!changes) { if (!changes) {
// try to fetch the data // try to fetch the data
await actions.fetch(branch.remote.remote, branch.name,null,20, true, false, true) await actions.fetch(branch.remote.name, branch.name,null,20, true, false, true)
} }
} }

@ -13,7 +13,7 @@ export const Fetch = () => {
return ( return (
<> <>
<div className="btn-group w-100" role="group"> <div className="btn-group w-100" role="group">
<GitUIButton disabledCondition={fetchIsDisabled()} type="button" onClick={async () => actions.fetch()} className="btn btn-primary mr-1 w-50"><div>Fetch {context.upstream && context.upstream.remote}</div></GitUIButton> <GitUIButton disabledCondition={fetchIsDisabled()} type="button" onClick={async () => actions.fetch()} className="btn btn-primary mr-1 w-50"><div>Fetch {context.upstream && context.upstream.name}</div></GitUIButton>
<GitUIButton disabledCondition={fetchIsDisabled()} type="button" onClick={async () => actions.fetch(null, null, context.currentBranch.name, null, true )} className="btn btn-primary w-50 long-and-truncated">Fetch {context.currentBranch.name}</GitUIButton> <GitUIButton disabledCondition={fetchIsDisabled()} type="button" onClick={async () => actions.fetch(null, null, context.currentBranch.name, null, true )} className="btn btn-primary w-50 long-and-truncated">Fetch {context.currentBranch.name}</GitUIButton>
</div> </div>
</>) </>)

@ -19,7 +19,7 @@ export const PushPull = () => {
useEffect(() => { useEffect(() => {
setRemoteBranch(context.currentBranch.name) setRemoteBranch(context.currentBranch.name)
setLocalBranch(context.currentBranch.name) setLocalBranch(context.currentBranch.name)
if ((!context.upstream) && context.currentBranch && context.currentBranch.remote && context.currentBranch.remote.remote) { if ((!context.upstream) && context.currentBranch && context.currentBranch.remote && context.currentBranch.remote.name) {
actions.setUpstreamRemote(context.currentBranch.remote) actions.setUpstreamRemote(context.currentBranch.remote)
} }
}, [context.currentBranch]) }, [context.currentBranch])
@ -33,7 +33,7 @@ export const PushPull = () => {
} }
const onRemoteChange = (value: string) => { const onRemoteChange = (value: string) => {
const remote: remote = context.remotes.find(r => r.remote === value) const remote: remote = context.remotes.find(r => r.name === value)
if (remote) { if (remote) {
actions.setUpstreamRemote(remote) actions.setUpstreamRemote(remote)
} }
@ -47,12 +47,12 @@ export const PushPull = () => {
const push = async () => { const push = async () => {
console.log('PUSH', context.upstream, localBranch, remoteBranch, force) console.log('PUSH', context.upstream, localBranch, remoteBranch, force)
await actions.push(context.upstream.remote, localBranch, remoteBranch, force) await actions.push(context.upstream.name, localBranch, remoteBranch, force)
await actions.fetch(context.upstream.remote, localBranch, remoteBranch, 1, true) await actions.fetch(context.upstream.name, localBranch, remoteBranch, 1, true)
} }
const pull = async () => { const pull = async () => {
actions.pull(context.upstream.remote, localBranch, remoteBranch) actions.pull(context.upstream.name, localBranch, remoteBranch)
} }
useEffect(() => { useEffect(() => {
@ -80,7 +80,7 @@ export const PushPull = () => {
// map context.repositories to options // map context.repositories to options
const options = context.remotes && context.remotes.length > 0 && context.remotes const options = context.remotes && context.remotes.length > 0 && context.remotes
.map(repo => { .map(repo => {
return { value: repo.remote, label: repo.remote } return { value: repo.name, label: repo.name }
}) })
setLocalRemotesOptions(options) setLocalRemotesOptions(options)
@ -132,7 +132,7 @@ export const PushPull = () => {
theme={selectTheme} theme={selectTheme}
styles={selectStyles} styles={selectStyles}
isClearable={true} isClearable={true}
value={{ value: context.upstream && context.upstream.remote, label: context.upstream && context.upstream.remote }} value={{ value: context.upstream && context.upstream.name, label: context.upstream && context.upstream.name }}
placeholder="Type to search for a branch..." placeholder="Type to search for a branch..."
/> />

@ -33,7 +33,7 @@ export const CommitDetails = (props: CommitDetailsProps) => {
const commitsAhead = (remote: remote) => { const commitsAhead = (remote: remote) => {
if (!remote) return []; if (!remote) return [];
return context.branchDifferences[`${remote.remote}/${branch.name}`]?.uniqueHeadCommits || []; return context.branchDifferences[`${remote.name}/${branch.name}`]?.uniqueHeadCommits || [];
} }
const isAheadOfRepo = () => { const isAheadOfRepo = () => {
@ -41,7 +41,7 @@ export const CommitDetails = (props: CommitDetailsProps) => {
} }
const openFileOnRemote = (file: string, hash: string) => { const openFileOnRemote = (file: string, hash: string) => {
console.log("open file on remote", file, hash, getRemote() ? `${getRemote().remote}/${branch.name}/commit/${hash}/${file}` : "") console.log("open file on remote", file, hash, getRemote() ? `${getRemote().name}/${branch.name}/commit/${hash}/${file}` : "")
if (!getRemote()) return if (!getRemote()) return
window.open(`${getRemote() ? `${getRemote().url}/blob/${hash}/${file}` : ""}`, "_blank") window.open(`${getRemote() ? `${getRemote().url}/blob/${hash}/${file}` : ""}`, "_blank")
} }

@ -19,7 +19,7 @@ export const Remotes = () => {
const addRemote = async () => { const addRemote = async () => {
actions.addRemote({ actions.addRemote({
remote: remoteName, name: remoteName,
url: url url: url
}) })
} }

@ -34,7 +34,7 @@ export const Remoteselect = (props: RemoteSelectProps) => {
<RemotesDetailsNavigation callback={setActivePanel} eventKey="0" activePanel={activePanel} remote={remote} /> <RemotesDetailsNavigation callback={setActivePanel} eventKey="0" activePanel={activePanel} remote={remote} />
<Accordion.Collapse className="pl-2 border-left ml-1" eventKey="0"> <Accordion.Collapse className="pl-2 border-left ml-1" eventKey="0">
<> <>
{context.branches && context.branches.filter((branch, index) => branch.remote && branch.remote.remote === remote.remote ).map((branch, index) => { {context.branches && context.branches.filter((branch, index) => branch.remote && branch.remote.name === remote.name ).map((branch, index) => {
return ( return (
<RemoteBranchDetails key={index} branch={branch}></RemoteBranchDetails> <RemoteBranchDetails key={index} branch={branch}></RemoteBranchDetails>
); );

@ -54,7 +54,7 @@ export const RemotesImport = () => {
const addRemote = async () => { const addRemote = async () => {
try { try {
actions.addRemote({ actions.addRemote({
remote: remoteName, name: remoteName,
url: repo.html_url url: repo.html_url
}) })
} catch (e) { } catch (e) {

@ -36,41 +36,7 @@ const statusmatrix: statusMatrixType[] = fileStatuses.map((x: any) => {
status: x, status: x,
}; };
}); });
/*
interface customDGitSystem extends IDgitSystem{
events: StatusEvents,
methods: {
getCommitChanges(oid1: string, oid2: string): Promise<commitChange[]>
getBranchCommits(branch: branch): Promise<ReadCommitResult[]>
fetchBranch(branch: branch): Promise<any>
remotebranches(owner: string, repo: string): Promise<branch[]>
remoteCommits(url: string, branch: string, length: number): Promise<ReadCommitResult[]>
repositories(token: string): Promise<any>
clone(url: string, branch: string, depth: number, singleBranch: boolean): Promise<any>
getGitHubUser(token: string): Promise<{ user: GitHubUser, ratelimit: RateLimit }>
saveGitHubCredentials(credentials: { username: string, email: string, token: string }): Promise<any>
getGitHubCredentials(): Promise<{ username: string, email: string, token: string }>
currentbranch(): Promise<branch>
}
}
interface notificationSystem {
methods: {
toast(message: string): void
alert(message: {
title: string,
type: string
}): void
modal(modal: AlertModal): void
},
events: StatusEvents
}
interface customApi extends IRemixApi {
dGitProvider: customDGitSystem
notification: notificationSystem
}
*/
let plugin: Plugin, dispatch: React.Dispatch<gitActionDispatch> let plugin: Plugin, dispatch: React.Dispatch<gitActionDispatch>
@ -173,7 +139,7 @@ export const currentBranch = async () => {
(await plugin.call("dGitProvider", "currentbranch")) || { (await plugin.call("dGitProvider", "currentbranch")) || {
name: "", name: "",
remote: { remote: {
remote: "", name: "",
url: "", url: "",
}, },
}; };
@ -717,7 +683,7 @@ export const getCommitChanges = async (oid1: string, oid2: string, branch?: bran
const foundCommit = log.find((commit: ReadCommitResult) => commit.oid === oid2) const foundCommit = log.find((commit: ReadCommitResult) => commit.oid === oid2)
if (!foundCommit && remote) { if (!foundCommit && remote) {
console.log('getCommitChanges fetching remote') console.log('getCommitChanges fetching remote')
await fetch(remote ? remote.remote : null, branch ? branch.name : null, null, 5, true, true) await fetch(remote ? remote.name : null, branch ? branch.name : null, null, 5, true, true)
} }
} }
const result: commitChange[] = await plugin.call('dGitProvider', 'getCommitChanges', oid1, oid2) const result: commitChange[] = await plugin.call('dGitProvider', 'getCommitChanges', oid1, oid2)
@ -759,7 +725,7 @@ export const getBranchDifferences = async (branch: branch, remote: remote, state
if (state.defaultRemote){ if (state.defaultRemote){
remote = state.defaultRemote remote = state.defaultRemote
} else { } else {
remote = state.remotes.find((remote: remote) => remote.remote === 'origin') remote = state.remotes.find((remote: remote) => remote.name === 'origin')
} }
if (!remote && state.remotes[0]){ if (!remote && state.remotes[0]){
remote = state.remotes[0] remote = state.remotes[0]

@ -148,7 +148,7 @@ export const gitReducer = (state: gitState = defaultGitState, action: Action): g
case 'SET_BRANCH_DIFFERENCES': case 'SET_BRANCH_DIFFERENCES':
state.branchDifferences[`${(action as setBranchDifferencesAction).payload.remote.remote}/${(action as setBranchDifferencesAction).payload.branch.name}`] = (action as setBranchDifferencesAction).payload.branchDifference state.branchDifferences[`${(action as setBranchDifferencesAction).payload.remote.name}/${(action as setBranchDifferencesAction).payload.branch.name}`] = (action as setBranchDifferencesAction).payload.branchDifference
return { return {
...state, ...state,

@ -108,7 +108,7 @@ export type branch = {
} }
export type remote = { export type remote = {
remote: string name: string
url: string url: string
} }
@ -117,7 +117,7 @@ export type remoteBranch = {
} }
export const defaultGitState: gitState = { export const defaultGitState: gitState = {
currentBranch: { name: "", remote: { remote: "", url: "" } }, currentBranch: { name: "", remote: { name: "", url: "" } },
commits: [], commits: [],
branch: "", branch: "",
canCommit: true, canCommit: true,

Loading…
Cancel
Save