git4refactor
filip mertens 6 months ago
parent e1c1d94336
commit c46e181394
  1. 3
      libs/remix-ui/git/src/components/gitui.tsx
  2. 1
      libs/remix-ui/git/src/components/panels/branches/localbranchdetails.tsx
  3. 2
      libs/remix-ui/git/src/components/panels/commands/fetch.tsx
  4. 5
      libs/remix-ui/git/src/components/panels/commands/pushpull.tsx
  5. 105
      libs/remix-ui/git/src/lib/gitactions.ts
  6. 3
      libs/remix-ui/git/src/state/context.tsx

@ -1,5 +1,5 @@
import React, { useEffect, useReducer, useState } from 'react'
import { add, addall, checkout, checkoutfile, clone, commit, createBranch, remoteBranches, repositories, rm, getCommitChanges, diff, resolveRef, getBranchCommits, setUpstreamRemote, getGitHubUser, getBranches, getRemotes, remoteCommits, saveGitHubCredentials, getGitHubCredentials, fetch, pull, push, setDefaultRemote, addRemote, removeRemote, sendToGitLog, clearGitLog } from '../lib/gitactions'
import { add, addall, checkout, checkoutfile, clone, commit, createBranch, remoteBranches, repositories, rm, getCommitChanges, diff, resolveRef, getBranchCommits, setUpstreamRemote, getGitHubUser, getBranches, getRemotes, remoteCommits, saveGitHubCredentials, getGitHubCredentials, fetch, pull, push, setDefaultRemote, addRemote, removeRemote, sendToGitLog, clearGitLog, getBranchDifferences } from '../lib/gitactions'
import { loadFiles, setCallBacks } from '../lib/listeners'
import { openDiff, openFile, saveToken, setModifiedDecorator, setPlugin, setUntrackedDecorator, statusChanged } from '../lib/pluginActions'
import { gitActionsContext, pluginActionsContext } from '../state/context'
@ -101,6 +101,7 @@ export const GitUI = (props: IGitUi) => {
remoteBranches,
getCommitChanges,
getBranchCommits,
getBranchDifferences,
diff,
resolveRef,
setUpstreamRemote,

@ -28,6 +28,7 @@ export const LocalBranchDetails = (props: BrancheDetailsProps) => {
console.log('GET BRANCH COMMITS', branch)
if (lastPageNumber === 0)
actions.getBranchCommits(branch, 1)
actions.getBranchDifferences(branch, null, context)
}
}, [activePanel])

@ -14,7 +14,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"><>Fetch {context.upstream}</></GitUIButton>
<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(null, null, context.currentBranch.name, null, true )} className="btn btn-primary w-50 long-and-truncated">Fetch {context.currentBranch.name}</GitUIButton>
</div>
</>)

@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
import { gitActionsContext } from "../../../state/context";
import { gitPluginContext } from "../../gitui";
import { selectStyles, selectTheme } from "../../../types/styles";
import Select from 'react-select'
import Select, { Options, OptionsOrGroups } from 'react-select'
import GitUIButton from "../../buttons/gituibutton";
import { remote } from "../../../types";
@ -20,6 +20,7 @@ export const PushPull = () => {
setRemoteBranch(context.currentBranch.name)
setLocalBranch(context.currentBranch.name)
if ((!context.upstream) && context.currentBranch && context.currentBranch.remote && context.currentBranch.remote.remote) {
console.log('SET UPSTREAM', context.currentBranch.remote)
actions.setUpstreamRemote(context.currentBranch.remote)
}
}, [context.currentBranch])
@ -145,7 +146,7 @@ export const PushPull = () => {
theme={selectTheme}
styles={selectStyles}
isClearable={true}
value={{ value: context.upstream, label: context.upstream }}
value={{ value: context.upstream && context.upstream.remote, label: context.upstream && context.upstream.remote }}
placeholder="Type to search for a branch..."
/>

@ -6,7 +6,7 @@ import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusM
import { removeSlash } from "../utils";
import { disableCallBacks, enableCallBacks } from "./listeners";
import { AlertModal, ModalTypes } from "@remix-ui/app";
import { gitActionsContext } from "../state/context";
import { gitActions, gitActionsContext } from "../state/context";
import { gitPluginContext } from "../components/gitui";
import { setFileDecorators } from "./pluginActions";
import { IDgitSystem, IRemixApi, RemixApi } from "@remixproject/plugin-api";
@ -694,52 +694,6 @@ export const diff = async (commitChange: commitChange) => {
commitChange.original = "";
}
/*
const fullfilename = args; // $(args[0].currentTarget).data('file')
try {
const commitOid = await client.call(
"dGitProvider",
"resolveref",
{ ref: "HEAD" }
);
const { blob } = await client.call("dGitProvider", "readblob", {
oid: commitOid,
filepath: removeSlash(fullfilename),
});
const newcontent = await client.call(
"fileManager",
"readFile",//
removeSlash(fullfilename)
);
// Utils.log(original);
//Utils.log(newcontent);
//const filediff = createPatch(filename, original, newcontent); // diffLines(original,newcontent)
////Utils.log(filediff)
const filediff: diffObject = {
originalFileName: fullfilename,
updatedFileName: fullfilename,
current: newcontent,
past: original,
};
return filediff;
} catch (e) {
const filediff: diffObject = {
originalFileName: "",
updatedFileName: "",
current: "",
past: "",
};
return filediff;
}
*/
}
export const getCommitChanges = async (oid1: string, oid2: string, branch?: branch, remote?: remote) => {
@ -793,57 +747,22 @@ export const fetchBranch = async (branch: branch, page: number) => {
console.log(rc, 'remote commits from octokit')
dispatch(setRemoteBranchCommits({ branch, commits: rc }))
return
const r = await plugin.call('dGitProvider', 'fetch', {
ref: branch.name,
remoteRef: branch.name,
singleBranch: true,
remote: branch.remote.remote,
depth: 10
})
console.log(branch)
const remoteCommits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', {
ref: r.fetchHead
})
console.log(r, remoteCommits)
let localCommits: ReadCommitResult[] = []
try {
localCommits = await plugin.call('dGitProvider', 'log', {
ref: branch.name,
})
console.log(r, localCommits)
} catch (e) { }
}
const remoteCommitsThatAreNotLocal: ReadCommitResult[] = remoteCommits.filter((commit) => {
return !localCommits.find((localCommit) => localCommit.oid === commit.oid)
}
)
console.log(remoteCommitsThatAreNotLocal)
const mergeCommits = remoteCommitsThatAreNotLocal.map((commit) => {
return {
...commit,
remote: true
export const getBranchDifferences = async (branch: branch, remote: remote, state: gitState) => {
if(!remote && state){
if(state.defaultRemote){
remote = state.defaultRemote
}else{
remote = state.remotes.find((remote: remote) => remote.remote === 'origin')
}
}).concat(localCommits.map((commit) => {
return {
...commit,
remote: false
if(!remote && state.remotes[0]){
remote = state.remotes[0]
}
}
))
// sort by date
mergeCommits.sort((a, b) => {
return new Date(b.commit.committer.timestamp).getTime() - new Date(a.commit.committer.timestamp).getTime()
})
console.log(mergeCommits)
//console.log(r, commits)
//dispatch(setRemoteBranchCommits({ branch, commits: mergeCommits }))
}
export const getBranchDifferences = async (branch: branch, remote: remote) => {
if(!remote) return
try {
console.log('compare', branch, remote)
const branchDifference: branchDifference = await plugin.call('dGitProvider', 'compareBranches', {
branch,
remote

@ -1,6 +1,6 @@
import { ReadCommitResult } from "isomorphic-git"
import React from "react"
import { branch, commitChange, gitLog, remote } from "../types"
import { branch, commitChange, gitLog, gitState, remote } from "../types"
export interface gitActions {
removeRemote(remote: remote): void
@ -19,6 +19,7 @@ export interface gitActions {
remoteBranches(owner: string, repo: string): Promise<any>
getCommitChanges(oid1: string, oid2: string, branch?: branch, remote?: remote): Promise<commitChange[] | boolean>
getBranchCommits(branch: branch, page: number): Promise<void>
getBranchDifferences(branch: branch, remote?: remote, state?: gitState): Promise<void>
getGitHubUser(): Promise<any>
diff(commitChange: commitChange): Promise<void>
resolveRef(ref: string): Promise<string>

Loading…
Cancel
Save