change upstream object

git4refactor
filip mertens 7 months ago
parent 5b3df39c37
commit e1c1d94336
  1. 2
      apps/remix-ide/src/app/files/dgitProvider.ts
  2. 2
      apps/remix-ide/src/app/files/fileManager.ts
  3. 2
      libs/remix-ui/git/src/components/buttons/sourcecontrolbuttons.tsx
  4. 6
      libs/remix-ui/git/src/components/panels/commands/fetch.tsx
  5. 21
      libs/remix-ui/git/src/components/panels/commands/pushpull.tsx
  6. 2
      libs/remix-ui/git/src/components/panels/commits.tsx
  7. 34
      libs/remix-ui/git/src/lib/gitactions.ts
  8. 2
      libs/remix-ui/git/src/state/context.tsx
  9. 2
      libs/remix-ui/git/src/state/gitpayload.ts
  10. 4
      libs/remix-ui/git/src/state/gitreducer.tsx
  11. 6
      libs/remix-ui/git/src/types/index.ts

@ -1105,7 +1105,7 @@ class DGitProvider extends Plugin {
const accessToken = input.token; const accessToken = input.token;
let page = input.page || 1 const page = input.page || 1
const perPage = input.per_page || 10 const perPage = input.per_page || 10
const baseURL = 'https://api.github.com/user/repos' const baseURL = 'https://api.github.com/user/repos'

@ -723,7 +723,7 @@ class FileManager extends Plugin {
async closeDiff(change: commitChange) { async closeDiff(change: commitChange) {
if(!change.readonly){ if(!change.readonly){
let file = this.normalize(change.path) const file = this.normalize(change.path)
delete this.openedFiles[file] delete this.openedFiles[file]
if (!Object.keys(this.openedFiles).length) { if (!Object.keys(this.openedFiles).length) {
this._deps.config.set('currentFile', '') this._deps.config.set('currentFile', '')

@ -87,7 +87,7 @@ export const SourceControlButtons = (props: SourceControlButtonsProps) => {
} }
const buttonsDisabled = () => { const buttonsDisabled = () => {
return context.upstream === '' || context.remotes.length === 0 return (!context.upstream) || context.remotes.length === 0
} }

@ -9,13 +9,13 @@ export const Fetch = () => {
const context = React.useContext(gitPluginContext) const context = React.useContext(gitPluginContext)
const fetchIsDisabled = () => { const fetchIsDisabled = () => {
return context.upstream === '' || context.remotes.length === 0 return (!context.upstream) || context.remotes.length === 0
} }
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">Fetch {context.upstream}</GitUIButton> <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(null, null, context.currentBranch.name, null, true )} className="btn btn-primary">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>
</>) </>)
} }

@ -2,9 +2,9 @@ import React, { useEffect, useState } from "react";
import { gitActionsContext } from "../../../state/context"; import { gitActionsContext } from "../../../state/context";
import { gitPluginContext } from "../../gitui"; import { gitPluginContext } from "../../gitui";
import { selectStyles, selectTheme } from "../../../types/styles"; import { selectStyles, selectTheme } from "../../../types/styles";
import Select, { Options, OptionsOrGroups } from 'react-select' import Select from 'react-select'
import { setUpstream } from "../../../state/gitpayload";
import GitUIButton from "../../buttons/gituibutton"; import GitUIButton from "../../buttons/gituibutton";
import { remote } from "../../../types";
export const PushPull = () => { export const PushPull = () => {
const context = React.useContext(gitPluginContext) const context = React.useContext(gitPluginContext)
@ -19,8 +19,8 @@ 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.upstream === '') && context.currentBranch && context.currentBranch.remote && context.currentBranch.remote.remote) { if ((!context.upstream) && context.currentBranch && context.currentBranch.remote && context.currentBranch.remote.remote) {
actions.setUpstreamRemote(context.currentBranch.remote.remote) actions.setUpstreamRemote(context.currentBranch.remote)
} }
}, [context.currentBranch]) }, [context.currentBranch])
@ -35,9 +35,12 @@ export const PushPull = () => {
setLocalBranch(value) setLocalBranch(value)
} }
const onRemoteChange = (value: any) => { const onRemoteChange = (value: string) => {
console.log('onRemoteChange', value, context) console.log('onRemoteChange', value, context)
actions.setUpstreamRemote(value) const remote: remote = context.remotes.find(r => r.remote === value)
if(remote) {
actions.setUpstreamRemote(remote)
}
} }
useEffect(() => { useEffect(() => {
@ -52,11 +55,11 @@ 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)
actions.push(context.upstream, localBranch, remoteBranch, force) actions.push(context.upstream.remote, localBranch, remoteBranch, force)
} }
const pull = async () => { const pull = async () => {
actions.pull(context.upstream, localBranch, remoteBranch) actions.pull(context.upstream.remote, localBranch, remoteBranch)
} }
@ -94,7 +97,7 @@ export const PushPull = () => {
const pushPullIsDisabled = () => { const pushPullIsDisabled = () => {
return localBranch === '' || remoteBranch === '' || context.upstream === '' || context.remotes.length === 0 return localBranch === '' || remoteBranch === '' || !context.upstream || context.remotes.length === 0
} }

@ -35,7 +35,7 @@ export const Commits = () => {
} }
const fetchIsDisabled = () => { const fetchIsDisabled = () => {
return context.upstream === '' || context.remotes.length === 0 return (!context.upstream)|| context.remotes.length === 0
} }
return ( return (

@ -93,7 +93,7 @@ export const getRemotes = async () => {
dispatch(setRemotes(remotes)); dispatch(setRemotes(remotes));
} }
export const setUpstreamRemote = async (remote: string) => { export const setUpstreamRemote = async (remote: remote) => {
dispatch(setUpstream(remote)); dispatch(setUpstream(remote));
} }
@ -842,34 +842,34 @@ export const fetchBranch = async (branch: branch, page: number) => {
//dispatch(setRemoteBranchCommits({ branch, commits: mergeCommits })) //dispatch(setRemoteBranchCommits({ branch, commits: mergeCommits }))
} }
export const getBranchCommits = async (branch: branch, page: number) => { export const getBranchDifferences = async (branch: branch, remote: remote) => {
dispatch(setLoading(true))
await disableCallBacks()
try {
console.log(branch)
if (!branch.remote) {
const commits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', {
ref: branch.name,
})
try { try {
const branchDifference: branchDifference = await plugin.call('dGitProvider', 'compareBranches', { const branchDifference: branchDifference = await plugin.call('dGitProvider', 'compareBranches', {
branch, branch,
remote: { remote
remote: 'origin',
url: ''
}
}) })
console.log(commits, branchDifference)
dispatch(setBranchDifferences( dispatch(setBranchDifferences(
{ {
branch, branch,
remote: remote,
{ remote: 'origin', url: '' },
branchDifference: branchDifference branchDifference: branchDifference
})) }))
} catch (e) { } catch (e) {
} }
}
export const getBranchCommits = async (branch: branch, page: number) => {
dispatch(setLoading(true))
await disableCallBacks()
try {
console.log(branch)
if (!branch.remote) {
const commits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', {
ref: branch.name,
})
console.log(commits)
dispatch(setLocalBranchCommits({ branch, commits })) dispatch(setLocalBranchCommits({ branch, commits }))
} else { } else {
await fetchBranch(branch, page) await fetchBranch(branch, page)

@ -22,7 +22,7 @@ export interface gitActions {
getGitHubUser(): Promise<any> getGitHubUser(): Promise<any>
diff(commitChange: commitChange): Promise<void> diff(commitChange: commitChange): Promise<void>
resolveRef(ref: string): Promise<string> resolveRef(ref: string): Promise<string>
setUpstreamRemote(upstream: string): Promise<void> setUpstreamRemote(upstream: remote): Promise<void>
getBranches: () => Promise<void> getBranches: () => Promise<void>
getRemotes: () => Promise<void> getRemotes: () => Promise<void>
setDefaultRemote: (remote: remote) => Promise<void> setDefaultRemote: (remote: remote) => Promise<void>

@ -115,7 +115,7 @@ export const setRemotes = (remotes: remote[]) => {
} }
} }
export const setUpstream = (upstream: string) => { export const setUpstream = (upstream: remote) => {
return { return {
type: 'SET_UPSTREAM', type: 'SET_UPSTREAM',
payload: upstream payload: upstream

@ -1,6 +1,6 @@
import { ReadCommitResult } from "isomorphic-git" import { ReadCommitResult } from "isomorphic-git"
import { allChangedButNotStagedFiles, getFilesByStatus, getFilesWithNotModifiedStatus } from "../lib/fileHelpers" import { allChangedButNotStagedFiles, getFilesByStatus, getFilesWithNotModifiedStatus } from "../lib/fileHelpers"
import { branch, commitChange, defaultGitState, fileStatusResult, gitState, setRemoteBranchCommitsAction, setLocalBranchCommitsAction, setBranchDifferencesAction, setDefaultRemoteAction, setRemotesAction } from "../types" import { branch, commitChange, defaultGitState, fileStatusResult, gitState, setRemoteBranchCommitsAction, setLocalBranchCommitsAction, setBranchDifferencesAction, setDefaultRemoteAction, setRemotesAction, setUpstreamAction } from "../types"
interface Action { interface Action {
type: string type: string
@ -105,7 +105,7 @@ export const gitReducer = (state: gitState = defaultGitState, action: Action): g
case 'SET_UPSTREAM': case 'SET_UPSTREAM':
return { return {
...state, ...state,
upstream: action.payload upstream: (action as setUpstreamAction).payload
} }
case 'SET_COMMIT_CHANGES': case 'SET_COMMIT_CHANGES':

@ -30,7 +30,7 @@ export type gitState = {
syncStatus: syncStatus, syncStatus: syncStatus,
localCommitCount: number localCommitCount: number
remoteCommitCount: number remoteCommitCount: number
upstream: string upstream: remote
gitHubUser: GitHubUser gitHubUser: GitHubUser
rateLimit: RateLimit rateLimit: RateLimit
gitHubScopes: string[] gitHubScopes: string[]
@ -143,7 +143,7 @@ export const defaultGitState: gitState = {
syncStatus: syncStatus.none, syncStatus: syncStatus.none,
localCommitCount: 0, localCommitCount: 0,
remoteCommitCount: 0, remoteCommitCount: 0,
upstream: "", upstream: null,
gitHubUser: {} as GitHubUser, gitHubUser: {} as GitHubUser,
rateLimit: {} as RateLimit, rateLimit: {} as RateLimit,
gitHubScopes: [], gitHubScopes: [],
@ -231,7 +231,7 @@ export interface setRemotesAction {
export interface setUpstreamAction { export interface setUpstreamAction {
type: string, type: string,
payload: string payload: remote
} }
export interface setRemoteBranchCommitsAction { export interface setRemoteBranchCommitsAction {

Loading…
Cancel
Save