remote commits

git4refactor
filip mertens 9 months ago
parent 82caba939f
commit 6beeda8c6f
  1. 51
      libs/remix-ui/git/src/lib/gitactions.ts
  2. 2
      libs/remix-ui/git/src/state/context.tsx

@ -373,7 +373,7 @@ export const clone = async (url: string, branch: string, depth: number, singleBr
dispatch(setLoading(false)) dispatch(setLoading(false))
} }
export const fetch = async(remote?: string, ref?: string, remoteRef?: string) => { export const fetch = async (remote?: string, ref?: string, remoteRef?: string) => {
try { try {
await plugin.call('dGitProvider' as any, 'fetch', { remote, ref, remoteRef }) await plugin.call('dGitProvider' as any, 'fetch', { remote, ref, remoteRef })
await gitlog() 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 { try {
await plugin.call('dGitProvider' as any, 'pull', { remote, ref, remoteRef }) await plugin.call('dGitProvider' as any, 'pull', { remote, ref, remoteRef })
await gitlog() 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 { try {
await plugin.call('dGitProvider' as any, 'push', { remote, ref, remoteRef, force }) await plugin.call('dGitProvider' as any, 'push', { remote, ref, remoteRef, force })
} catch (e: any) { } catch (e: any) {
@ -643,8 +643,6 @@ export const diff = async (commitChange: commitChange) => {
} }
/* /*
const fullfilename = args; // $(args[0].currentTarget).data('file') const fullfilename = args; // $(args[0].currentTarget).data('file')
try { try {
@ -706,23 +704,58 @@ export const fetchBranch = async (branch: branch) => {
remote: branch.remote.remote, remote: branch.remote.remote,
depth: 10 depth: 10
}) })
const commits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', { const remoteCommits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', {
ref: r.fetchHead ref: r.fetchHead
}) })
console.log(r, commits) console.log(r, remoteCommits)
dispatch(setBranchCommits({ branch, commits })) 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) => { export const getBranchCommits = async (branch: branch) => {
try { try {
console.log(branch) console.log(branch)
if (!branch.remote) {
const commits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', { const commits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', {
ref: branch.name, ref: branch.name,
}) })
console.log(commits) console.log(commits)
dispatch(setBranchCommits({ branch, commits })) dispatch(setBranchCommits({ branch, commits }))
} else {
await fetchBranch(branch) await fetchBranch(branch)
return commits }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
await fetchBranch(branch) await fetchBranch(branch)

@ -17,7 +17,7 @@ export interface gitActions {
createBranch(branch: string): Promise<void> createBranch(branch: string): Promise<void>
remoteBranches(owner: string, repo: string): Promise<any> remoteBranches(owner: string, repo: string): Promise<any>
getCommitChanges(oid1: string, oid2: string): Promise<commitChange[]> getCommitChanges(oid1: string, oid2: string): Promise<commitChange[]>
getBranchCommits(branch: branch): Promise<ReadCommitResult[]> getBranchCommits(branch: branch): Promise<void>
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>

Loading…
Cancel
Save