remote refactor

git4refactor
filip mertens 6 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 = () => {
return getRemote() ? getRemote().remote : ''
return getRemote() ? getRemote().name : ''
}
const sync = async() => {

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

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

@ -57,7 +57,7 @@ export const BrancheDetailsNavigation = (props: BrancheDetailsNavigationProps) =
activePanel === eventKey ? <FontAwesomeIcon className='' icon={faCaretDown}></FontAwesomeIcon> : <FontAwesomeIcon className='' icon={faCaretRight}></FontAwesomeIcon>
}
<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>
{context.currentBranch.name === branch.name ?

@ -45,7 +45,7 @@ export const RemotesDetailsNavigation = (props: RemotesDetailsNavigationProps) =
}
<CustomTooltip tooltipText={remote.url} placement="top">
<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>
</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={async () => {
await actions.fetch(remote.remote)
await actions.fetch(remote.name)
}}><FontAwesomeIcon icon={faSync} ></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>}

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

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

@ -35,7 +35,7 @@ export const LocalBranchDetails = (props: BrancheDetailsProps) => {
const checkout = (branch: branch) => {
actions.checkout({
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) => {
await actions.checkout({
ref: branch.name,
remote: branch.remote && branch.remote.remote || null
remote: branch.remote && branch.remote.name || null
});
await actions.getBranches()
}
@ -74,7 +74,7 @@ export const RemoteBranchDetails = (props: BrancheDetailsProps) => {
console.log('CHANGES', changes)
if (!changes) {
// 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 (
<>
<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>
</div>
</>)

@ -19,7 +19,7 @@ export const PushPull = () => {
useEffect(() => {
setRemoteBranch(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)
}
}, [context.currentBranch])
@ -33,7 +33,7 @@ export const PushPull = () => {
}
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) {
actions.setUpstreamRemote(remote)
}
@ -47,12 +47,12 @@ export const PushPull = () => {
const push = async () => {
console.log('PUSH', context.upstream, localBranch, remoteBranch, force)
await actions.push(context.upstream.remote, localBranch, remoteBranch, force)
await actions.fetch(context.upstream.remote, localBranch, remoteBranch, 1, true)
await actions.push(context.upstream.name, localBranch, remoteBranch, force)
await actions.fetch(context.upstream.name, localBranch, remoteBranch, 1, true)
}
const pull = async () => {
actions.pull(context.upstream.remote, localBranch, remoteBranch)
actions.pull(context.upstream.name, localBranch, remoteBranch)
}
useEffect(() => {
@ -80,7 +80,7 @@ export const PushPull = () => {
// map context.repositories to options
const options = context.remotes && context.remotes.length > 0 && context.remotes
.map(repo => {
return { value: repo.remote, label: repo.remote }
return { value: repo.name, label: repo.name }
})
setLocalRemotesOptions(options)
@ -132,7 +132,7 @@ export const PushPull = () => {
theme={selectTheme}
styles={selectStyles}
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..."
/>

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

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

@ -34,7 +34,7 @@ export const Remoteselect = (props: RemoteSelectProps) => {
<RemotesDetailsNavigation callback={setActivePanel} eventKey="0" activePanel={activePanel} remote={remote} />
<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 (
<RemoteBranchDetails key={index} branch={branch}></RemoteBranchDetails>
);

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

@ -36,41 +36,7 @@ const statusmatrix: statusMatrixType[] = fileStatuses.map((x: any) => {
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>
@ -173,7 +139,7 @@ export const currentBranch = async () => {
(await plugin.call("dGitProvider", "currentbranch")) || {
name: "",
remote: {
remote: "",
name: "",
url: "",
},
};
@ -717,7 +683,7 @@ export const getCommitChanges = async (oid1: string, oid2: string, branch?: bran
const foundCommit = log.find((commit: ReadCommitResult) => commit.oid === oid2)
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.name : null, branch ? branch.name : null, null, 5, true, true)
}
}
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){
remote = state.defaultRemote
} else {
remote = state.remotes.find((remote: remote) => remote.remote === 'origin')
remote = state.remotes.find((remote: remote) => remote.name === 'origin')
}
if (!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':
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 {
...state,

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

Loading…
Cancel
Save