diff --git a/.changeset/few-plums-enjoy.md b/.changeset/few-plums-enjoy.md index 4b0e232b3b..4e2ee0f719 100644 --- a/.changeset/few-plums-enjoy.md +++ b/.changeset/few-plums-enjoy.md @@ -2,4 +2,7 @@ '@backstage/backend-common': patch --- -Updated Git to allow for bare clone +Updated the Git class with the following: + +- Added `depth` and `noCheckout` options to Git clone, using these you can create a bare clone that includes just the git history +- New `log` function which you can use to view the commit history of a git repo diff --git a/packages/backend-common/src/scm/git.test.ts b/packages/backend-common/src/scm/git.test.ts index abbafc375d..42ad152c05 100644 --- a/packages/backend-common/src/scm/git.test.ts +++ b/packages/backend-common/src/scm/git.test.ts @@ -105,6 +105,7 @@ describe('Git', () => { dir, singleBranch: true, depth: 1, + noCheckout: false, onProgress: expect.any(Function), headers: { 'user-agent': 'git/@isomorphic-git', @@ -320,4 +321,21 @@ describe('Git', () => { }); }); }); + + describe('log', () => { + it('should call isomorphic-git with the correct arguments', async () => { + const dir = '/some/mock/dir'; + const ref = 'as43bd7'; + + const git = Git.fromAuth({}); + + await git.log({ dir, ref }); + + expect(isomorphic.log).toHaveBeenCalledWith({ + fs, + dir, + ref, + }); + }); + }); }); diff --git a/packages/backend-common/src/scm/git.ts b/packages/backend-common/src/scm/git.ts index 0d4e768eae..9f36cc9d5b 100644 --- a/packages/backend-common/src/scm/git.ts +++ b/packages/backend-common/src/scm/git.ts @@ -76,7 +76,7 @@ export class Git { return git.commit({ fs, dir, message, author, committer }); } - // https://isomorphic-git.org/docs/en/clone + /** https://isomorphic-git.org/docs/en/clone */ async clone(options: { url: string; dir: string; @@ -103,7 +103,7 @@ export class Git { }); } - // https://isomorphic-git.org/docs/en/currentBranch + /** https://isomorphic-git.org/docs/en/currentBranch */ async currentBranch(options: { dir: string; fullName?: boolean; @@ -114,7 +114,7 @@ export class Git { >; } - // https://isomorphic-git.org/docs/en/fetch + /** https://isomorphic-git.org/docs/en/fetch */ async fetch(options: { dir: string; remote?: string }): Promise { const { dir, remote = 'origin' } = options; this.config.logger?.info( @@ -142,7 +142,7 @@ export class Git { }); } - // https://isomorphic-git.org/docs/en/merge + /** https://isomorphic-git.org/docs/en/merge */ async merge(options: { dir: string; theirs: string; @@ -184,7 +184,7 @@ export class Git { }); } - // https://isomorphic-git.org/docs/en/readCommit + /** https://isomorphic-git.org/docs/en/readCommit */ async readCommit(options: { dir: string; sha: string; @@ -193,13 +193,13 @@ export class Git { return git.readCommit({ fs, dir, oid: sha }); } - // https://isomorphic-git.org/docs/en/resolveRef + /** https://isomorphic-git.org/docs/en/resolveRef */ async resolveRef(options: { dir: string; ref: string }): Promise { const { dir, ref } = options; return git.resolveRef({ fs, dir, ref }); } - // https://isomorphic-git.org/docs/en/log + /** https://isomorphic-git.org/docs/en/log */ async log(options: { dir: string; ref?: string;