From 6beeda8c6f52ba4a2637db3de63b91bb4de8fa6c Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 24 Feb 2024 09:50:07 +0100 Subject: [PATCH] remote commits --- libs/remix-ui/git/src/lib/gitactions.ts | 63 +++++++++++++++++++------ libs/remix-ui/git/src/state/context.tsx | 2 +- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/libs/remix-ui/git/src/lib/gitactions.ts b/libs/remix-ui/git/src/lib/gitactions.ts index 5e89b1b92d..2792d2c346 100644 --- a/libs/remix-ui/git/src/lib/gitactions.ts +++ b/libs/remix-ui/git/src/lib/gitactions.ts @@ -373,7 +373,7 @@ export const clone = async (url: string, branch: string, depth: number, singleBr dispatch(setLoading(false)) } -export const fetch = async(remote?: string, ref?: string, remoteRef?: string) => { +export const fetch = async (remote?: string, ref?: string, remoteRef?: string) => { try { await plugin.call('dGitProvider' as any, 'fetch', { remote, ref, remoteRef }) await gitlog() @@ -383,7 +383,7 @@ export const fetch = async(remote?: string, ref?: string, remoteRef?: string) => } } -export const pull = async(remote?: string, ref?: string, remoteRef?: string) => { +export const pull = async (remote?: string, ref?: string, remoteRef?: string) => { try { await plugin.call('dGitProvider' as any, 'pull', { remote, ref, remoteRef }) await gitlog() @@ -392,7 +392,7 @@ export const pull = async(remote?: string, ref?: string, remoteRef?: string) => } } -export const push = async(remote?: string, ref?: string, remoteRef?: string, force?: boolean) => { +export const push = async (remote?: string, ref?: string, remoteRef?: string, force?: boolean) => { try { await plugin.call('dGitProvider' as any, 'push', { remote, ref, remoteRef, force }) } catch (e: any) { @@ -643,8 +643,6 @@ export const diff = async (commitChange: commitChange) => { } - - /* const fullfilename = args; // $(args[0].currentTarget).data('file') try { @@ -706,23 +704,58 @@ export const fetchBranch = async (branch: branch) => { remote: branch.remote.remote, depth: 10 }) - const commits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', { + const remoteCommits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', { ref: r.fetchHead }) - console.log(r, commits) - dispatch(setBranchCommits({ branch, commits })) + 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 + } + }).concat(localCommits.map((commit) => { + return { + ...commit, + remote: false + } + } + )) + // 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(setBranchCommits({ branch, commits: mergeCommits })) } export const getBranchCommits = async (branch: branch) => { try { console.log(branch) - const commits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', { - ref: branch.name, - }) - console.log(commits) - dispatch(setBranchCommits({ branch, commits })) - await fetchBranch(branch) - return commits + if (!branch.remote) { + const commits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', { + ref: branch.name, + }) + console.log(commits) + dispatch(setBranchCommits({ branch, commits })) + } else { + await fetchBranch(branch) + } } catch (e) { console.log(e) await fetchBranch(branch) diff --git a/libs/remix-ui/git/src/state/context.tsx b/libs/remix-ui/git/src/state/context.tsx index 373c29bbc9..fa932b992e 100644 --- a/libs/remix-ui/git/src/state/context.tsx +++ b/libs/remix-ui/git/src/state/context.tsx @@ -17,7 +17,7 @@ export interface gitActions { createBranch(branch: string): Promise remoteBranches(owner: string, repo: string): Promise getCommitChanges(oid1: string, oid2: string): Promise - getBranchCommits(branch: branch): Promise + getBranchCommits(branch: branch): Promise getGitHubUser(): Promise diff(commitChange: commitChange): Promise resolveRef(ref: string): Promise