diff --git a/apps/remix-ide/src/app/files/dgitProvider.ts b/apps/remix-ide/src/app/files/dgitProvider.ts index 3f0a510bd2..41a348f07a 100644 --- a/apps/remix-ide/src/app/files/dgitProvider.ts +++ b/apps/remix-ide/src/app/files/dgitProvider.ts @@ -301,32 +301,7 @@ class DGitProvider extends Plugin { if ((Registry.getInstance().get('platform').api.isDesktop())) { return await this.call('isogit', 'compareBranches', { branch, remote }) } - // Get current branch commits - const headCommits = await git.log({ - ...await this.addIsomorphicGitConfigFS(), - ref: branch.name, - }); - - // Get remote branch commits - const remoteCommits = await git.log({ - ...await this.addIsomorphicGitConfigFS(), - ref: `${remote.name}/${branch.name}`, - }); - - // Convert arrays of commit objects to sets of commit SHAs - const headCommitSHAs = new Set(headCommits.map(commit => commit.oid)); - const remoteCommitSHAs = new Set(remoteCommits.map(commit => commit.oid)); - - // Filter out commits that are only in the remote branch - const uniqueRemoteCommits = remoteCommits.filter(commit => !headCommitSHAs.has(commit.oid)); - - // filter out commits that are only in the local branch - const uniqueHeadCommits = headCommits.filter(commit => !remoteCommitSHAs.has(commit.oid)); - - return { - uniqueHeadCommits, - uniqueRemoteCommits, - }; + return await isoGit.compareBranches({ branch, remote }, await this.addIsomorphicGitConfigFS()) } async getCommitChanges(commitHash1: string, commitHash2: string): Promise { diff --git a/apps/remixdesktop/src/plugins/isoGitPlugin.ts b/apps/remixdesktop/src/plugins/isoGitPlugin.ts index ce6c3268ba..bb79ff7d62 100644 --- a/apps/remixdesktop/src/plugins/isoGitPlugin.ts +++ b/apps/remixdesktop/src/plugins/isoGitPlugin.ts @@ -390,33 +390,7 @@ class IsoGitPluginClient extends ElectronBasePluginClient { } async compareBranches({ branch, remote }: compareBranchesInput): Promise { - - // Get current branch commits - const headCommits = await git.log({ - ...await this.getGitConfig(), - ref: branch.name, - }); - - // Get remote branch commits - const remoteCommits = await git.log({ - ...await this.getGitConfig(), - ref: `${remote.name}/${branch.name}`, - }); - - // Convert arrays of commit objects to sets of commit SHAs - const headCommitSHAs = new Set(headCommits.map(commit => commit.oid)); - const remoteCommitSHAs = new Set(remoteCommits.map(commit => commit.oid)); - - // Filter out commits that are only in the remote branch - const uniqueRemoteCommits = remoteCommits.filter(commit => !headCommitSHAs.has(commit.oid)); - - // filter out commits that are only in the local branch - const uniqueHeadCommits = headCommits.filter(commit => !remoteCommitSHAs.has(commit.oid)); - - return { - uniqueHeadCommits, - uniqueRemoteCommits, - }; + return await isoGit.compareBranches({ branch, remote }, await this.getGitConfig()) } } diff --git a/libs/remix-git/src/isogit.ts b/libs/remix-git/src/isogit.ts index 44ad3fcb3e..bd3b608203 100644 --- a/libs/remix-git/src/isogit.ts +++ b/libs/remix-git/src/isogit.ts @@ -1,4 +1,4 @@ -import { branch, commitChange, currentBranchInput, isoGitConfig, remote } from "@remix-api" +import { branch, commitChange, compareBranchesInput, currentBranchInput, isoGitConfig, remote } from "@remix-api" import git from 'isomorphic-git' const currentbranch = async (input: currentBranchInput, defaultConfig: isoGitConfig ) => { @@ -120,9 +120,40 @@ const currentbranch = async (input: currentBranchInput, defaultConfig: isoGitCon return result } + const compareBranches = async ({ branch, remote }: compareBranchesInput, defaultConfig: isoGitConfig) => { + + // Get current branch commits + const headCommits = await git.log({ + ...defaultConfig, + ref: branch.name, + }); + + // Get remote branch commits + const remoteCommits = await git.log({ + ...defaultConfig, + ref: `${remote.name}/${branch.name}`, + }); + + // Convert arrays of commit objects to sets of commit SHAs + const headCommitSHAs = new Set(headCommits.map(commit => commit.oid)); + const remoteCommitSHAs = new Set(remoteCommits.map(commit => commit.oid)); + + // Filter out commits that are only in the remote branch + const uniqueRemoteCommits = remoteCommits.filter(commit => !headCommitSHAs.has(commit.oid)); + + // filter out commits that are only in the local branch + const uniqueHeadCommits = headCommits.filter(commit => !remoteCommitSHAs.has(commit.oid)); + + return { + uniqueHeadCommits, + uniqueRemoteCommits, + }; + } + export const isoGit = { currentbranch, remotes, branches, - getCommitChanges + getCommitChanges, + compareBranches } \ No newline at end of file