@ -1,7 +1,7 @@
import { ViewPlugin } from "@remixproject/engine-web" ;
import { ReadBlobResult , ReadCommitResult } from "isomorphic-git" ;
import React from "react" ;
import { fileStatus , fileStatusMerge , setRemoteBranchCommits , setBranches , setCanCommit , setCommitChanges , setCommits , setCurrentBranch , setGitHubUser , setLoading , setRateLimit , setRemoteBranches , setRemotes , setRepos , setUpstream , setLocalBranchCommits , setBranchDifferences , setRemoteAsDefault , setScopes , setLog , clearLog } from "../state/gitpayload" ;
import { fileStatus , fileStatusMerge , setRemoteBranchCommits , resetRemoteBranchCommits , setBranches , setCanCommit , setCommitChanges , setCommits , setCurrentBranch , setGitHubUser , setLoading , setRateLimit , setRemoteBranches , setRemotes , setRepos , setUpstream , setLocalBranchCommits , setBranchDifferences , setRemoteAsDefault , setScopes , setLog , clearLog } from "../state/gitpayload" ;
import { GitHubUser , RateLimit , branch , commitChange , gitActionDispatch , statusMatrixType , gitState , branchDifference , remote , gitLog } from '../types' ;
import { removeSlash } from "../utils" ;
import { disableCallBacks , enableCallBacks } from "./listeners" ;
@ -428,6 +428,7 @@ const tokenWarning = async () => {
const parseError = async ( e : any ) = > {
console . log ( e )
// if message conttains 401 Unauthorized, show token warning
if ( e . message . includes ( '401' ) ) {
const result = await plugin . call ( 'notification' , 'modal' , {
@ -458,6 +459,13 @@ const parseError = async (e: any) => {
cancelLabel : 'Close' ,
type : ModalTypes . confirm
} )
} else if ( e . toString ( ) . includes ( 'NotFoundError' ) && ! e . toString ( ) . includes ( 'fetch' ) ) {
await plugin . call ( 'notification' , 'modal' , {
title : 'Remote branch not found' ,
message : 'The branch you are trying to fetch does not exist on the remote.\ If you have forked this branch from another branch, you may need to fetch the original branch first or publish this branch on the remote.' ,
okLabel : 'OK' ,
type : ModalTypes . alert
} )
} else {
await plugin . call ( 'notification' , 'alert' , {
title : 'Error' ,
@ -736,7 +744,18 @@ export const diff = async (commitChange: commitChange) => {
export const getCommitChanges = async ( oid1 : string , oid2 : string , branch? : branch , remote? : remote ) = > {
console . log ( oid1 , oid2 , branch , remote )
try {
// check if oid2 exists
const log = await plugin . call ( 'dGitProvider' , 'log' , {
ref : branch? branch . name : 'HEAD' ,
} )
if ( log ) {
const foundCommit = log . find ( ( commit : ReadCommitResult ) = > commit . oid === oid2 )
if ( ! foundCommit ) {
await fetch ( remote ? remote.remote : null , branch ? branch.name : null , null , 5 , true , true )
}
}
const result : commitChange [ ] = await plugin . call ( 'dGitProvider' , 'getCommitChanges' , oid1 , oid2 )
dispatch ( setCommitChanges ( result ) )
return result
@ -762,6 +781,9 @@ export const fetchBranch = async (branch: branch, page: number) => {
if ( ! branch . remote || ! branch . remote . url ) return
const token = await tokenWarning ( ) ;
console . log ( 'fetch' , branch )
if ( page == 1 ) {
dispatch ( resetRemoteBranchCommits ( { branch } ) )
}
const { owner , repo } = await getRepoDetails ( branch . remote . url ) ;
const rc = await plugin . call ( 'dGitProvider' as any , 'remotecommits' , { token , owner : owner , repo : repo , branch : branch.name , length , page } ) ;
console . log ( rc , 'remote commits from octokit' )
@ -825,7 +847,7 @@ export const getBranchCommits = async (branch: branch, page: number) => {
const commits : ReadCommitResult [ ] = await plugin . call ( 'dGitProvider' , 'log' , {
ref : branch.name ,
} )
try {
const branchDifference : branchDifference = await plugin . call ( 'dGitProvider' , 'compareBranches' , {
branch ,
remote : {
@ -841,12 +863,15 @@ export const getBranchCommits = async (branch: branch, page: number) => {
{ remote : 'origin' , url : '' } ,
branchDifference : branchDifference
} ) )
} catch ( e ) {
}
dispatch ( setLocalBranchCommits ( { branch , commits } ) )
} else {
await fetchBranch ( branch , page )
}
} catch ( e ) {
console . log ( e )
console . trace ( e )
await fetchBranch ( branch , page )
}
dispatch ( setLoading ( false ) )