import git from 'isomorphic-git'; import http from 'isomorphic-git/http/web'; import type { JSRuntimeFS } from './JSRuntime'; /** * Git class that wraps isomorphic-git and provides a cleaner interface. * Instantiate with an fs implementation, optional corsProxy string, and optional corsProxyRegex. * All methods have the same names as isomorphic-git but don't require * passing fs, http, and corsProxy each time. */ export class Git { private fs: JSRuntimeFS; private corsProxy?: string; constructor(fs: JSRuntimeFS, corsProxy?: string) { this.fs = fs; this.corsProxy = corsProxy; } // Repository initialization and configuration async init(options: Omit[0], 'fs'>) { return git.init({ fs: this.fs, ...options, }); } async clone(options: Omit[0], 'fs' | 'http' | 'corsProxy'>) { return git.clone({ fs: this.fs, http, corsProxy: this.corsProxy, ...options, }); } // Working with files async add(options: Omit[0], 'fs'>) { return git.add({ fs: this.fs, ...options, }); } async remove(options: Omit[0], 'fs'>) { return git.remove({ fs: this.fs, ...options, }); } async status(options: Omit[0], 'fs'>) { return git.status({ fs: this.fs, ...options, }); } async statusMatrix(options: Omit[0], 'fs'>) { return git.statusMatrix({ fs: this.fs, ...options, }); } // Commits and history async commit(options: Omit[0], 'fs'>) { return git.commit({ fs: this.fs, ...options, }); } async log(options: Omit[0], 'fs'>) { return git.log({ fs: this.fs, ...options, }); } async readCommit(options: Omit[0], 'fs'>) { return git.readCommit({ fs: this.fs, ...options, }); } // Branches async branch(options: Omit[0], 'fs'>) { return git.branch({ fs: this.fs, ...options, }); } async checkout(options: Omit[0], 'fs'>) { return git.checkout({ fs: this.fs, ...options, }); } async currentBranch(options: Omit[0], 'fs'>) { return git.currentBranch({ fs: this.fs, ...options, }); } async deleteBranch(options: Omit[0], 'fs'>) { return git.deleteBranch({ fs: this.fs, ...options, }); } async listBranches(options: Omit[0], 'fs'>) { return git.listBranches({ fs: this.fs, ...options, }); } // Remote operations async addRemote(options: Omit[0], 'fs'>) { return git.addRemote({ fs: this.fs, ...options, }); } async deleteRemote(options: Omit[0], 'fs'>) { return git.deleteRemote({ fs: this.fs, ...options, }); } async listRemotes(options: Omit[0], 'fs'>) { return git.listRemotes({ fs: this.fs, ...options, }); } async getRemoteInfo(options: Omit[0], 'http' | 'corsProxy'>) { return git.getRemoteInfo({ http, corsProxy: this.corsProxy, ...options, }); } async fetch(options: Omit[0], 'fs' | 'http' | 'corsProxy'>) { return git.fetch({ fs: this.fs, http, corsProxy: this.corsProxy, ...options, }); } async pull(options: Omit[0], 'fs' | 'http' | 'corsProxy'>) { return git.pull({ fs: this.fs, http, corsProxy: this.corsProxy, ...options, }); } async push(options: Omit[0], 'fs' | 'http' | 'corsProxy'>) { return git.push({ fs: this.fs, http, corsProxy: this.corsProxy, ...options, }); } // Tags async tag(options: Omit[0], 'fs'>) { return git.tag({ fs: this.fs, ...options, }); } async deleteTag(options: Omit[0], 'fs'>) { return git.deleteTag({ fs: this.fs, ...options, }); } async listTags(options: Omit[0], 'fs'>) { return git.listTags({ fs: this.fs, ...options, }); } // Configuration async getConfig(options: Omit[0], 'fs'>) { return git.getConfig({ fs: this.fs, ...options, }); } async setConfig(options: Omit[0], 'fs'>) { return git.setConfig({ fs: this.fs, ...options, }); } async getConfigAll(options: Omit[0], 'fs'>) { return git.getConfigAll({ fs: this.fs, ...options, }); } // Walking and comparisons async walk(options: Omit[0], 'fs'>) { return git.walk({ fs: this.fs, ...options, }); } // Reset operations async resetIndex(options: Omit[0], 'fs'>) { return git.resetIndex({ fs: this.fs, ...options, }); } // Object operations async readObject(options: Omit[0], 'fs'>) { return git.readObject({ fs: this.fs, ...options, }); } async writeObject(options: Omit[0], 'fs'>) { return git.writeObject({ fs: this.fs, ...options, }); } async readTree(options: Omit[0], 'fs'>) { return git.readTree({ fs: this.fs, ...options, }); } async writeTree(options: Omit[0], 'fs'>) { return git.writeTree({ fs: this.fs, ...options, }); } async readBlob(options: Omit[0], 'fs'>) { return git.readBlob({ fs: this.fs, ...options, }); } async writeBlob(options: Omit[0], 'fs'>) { return git.writeBlob({ fs: this.fs, ...options, }); } // Index operations async updateIndex(options: Omit[0], 'fs'>) { return git.updateIndex({ fs: this.fs, ...options, }); } // Merge operations async merge(options: Omit[0], 'fs'>) { return git.merge({ fs: this.fs, ...options, }); } async findMergeBase(options: Omit[0], 'fs'>) { return git.findMergeBase({ fs: this.fs, ...options, }); } // Utilities async isDescendent(options: Omit[0], 'fs'>) { return git.isDescendent({ fs: this.fs, ...options, }); } async findRoot(options: Omit[0], 'fs'>) { return git.findRoot({ fs: this.fs, ...options, }); } async getRemoteInfo2(options: Omit[0], 'http' | 'corsProxy'>) { return git.getRemoteInfo2({ http, corsProxy: this.corsProxy, ...options, }); } async listFiles(options: Omit[0], 'fs'>) { return git.listFiles({ fs: this.fs, ...options, }); } async hashBlob(options: Parameters[0]) { return git.hashBlob(options); } async annotatedTag(options: Omit[0], 'fs'>) { return git.annotatedTag({ fs: this.fs, ...options, }); } async readTag(options: Omit[0], 'fs'>) { return git.readTag({ fs: this.fs, ...options, }); } async writeTag(options: Omit[0], 'fs'>) { return git.writeTag({ fs: this.fs, ...options, }); } async writeRef(options: Omit[0], 'fs'>) { return git.writeRef({ fs: this.fs, ...options, }); } async deleteRef(options: Omit[0], 'fs'>) { return git.deleteRef({ fs: this.fs, ...options, }); } async listNotes(options: Omit[0], 'fs'>) { return git.listNotes({ fs: this.fs, ...options, }); } async readNote(options: Omit[0], 'fs'>) { return git.readNote({ fs: this.fs, ...options, }); } async addNote(options: Omit[0], 'fs'>) { return git.addNote({ fs: this.fs, ...options, }); } async removeNote(options: Omit[0], 'fs'>) { return git.removeNote({ fs: this.fs, ...options, }); } // Packfile operations async packObjects(options: Omit[0], 'fs'>) { return git.packObjects({ fs: this.fs, ...options, }); } async indexPack(options: Omit[0], 'fs'>) { return git.indexPack({ fs: this.fs, ...options, }); } // Additional utility methods async resolveRef(options: Omit[0], 'fs'>) { return git.resolveRef({ fs: this.fs, ...options, }); } async expandRef(options: Omit[0], 'fs'>) { return git.expandRef({ fs: this.fs, ...options, }); } async expandOid(options: Omit[0], 'fs'>) { return git.expandOid({ fs: this.fs, ...options, }); } async listRefs(options: Omit[0], 'fs'>) { return git.listRefs({ fs: this.fs, ...options, }); } async listServerRefs(options: Omit[0], 'http' | 'corsProxy'>) { return git.listServerRefs({ http, corsProxy: this.corsProxy, ...options, }); } async renameBranch(options: Omit[0], 'fs'>) { return git.renameBranch({ fs: this.fs, ...options, }); } async isIgnored(options: Omit[0], 'fs'>) { return git.isIgnored({ fs: this.fs, ...options, }); } async fastForward(options: Omit[0], 'fs'>) { return git.fastForward({ fs: this.fs, ...options, }); } async abortMerge(options: Omit[0], 'fs'>) { return git.abortMerge({ fs: this.fs, ...options, }); } async writeCommit(options: Omit[0], 'fs'>) { return git.writeCommit({ fs: this.fs, ...options, }); } // Version info version() { return git.version(); } }