From 3b24eaecbcbc48e635725ff3dfb6722546241ec4 Mon Sep 17 00:00:00 2001 From: "manuel.falcon" Date: Sat, 23 Dec 2023 11:28:51 +0100 Subject: [PATCH] Adding support for removing file from git index Signed-off-by: manuel.falcon --- .changeset/brave-shirts-hang.md | 5 +++++ packages/backend-common/src/scm/git.test.ts | 16 ++++++++++++++++ packages/backend-common/src/scm/git.ts | 9 +++++++++ 3 files changed, 30 insertions(+) create mode 100644 .changeset/brave-shirts-hang.md diff --git a/.changeset/brave-shirts-hang.md b/.changeset/brave-shirts-hang.md new file mode 100644 index 0000000000..07aeb514da --- /dev/null +++ b/.changeset/brave-shirts-hang.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-common': minor +--- + +Adding support for removing file from git index diff --git a/packages/backend-common/src/scm/git.test.ts b/packages/backend-common/src/scm/git.test.ts index 7533c6e2f3..1c07dfb917 100644 --- a/packages/backend-common/src/scm/git.test.ts +++ b/packages/backend-common/src/scm/git.test.ts @@ -63,6 +63,22 @@ describe('Git', () => { }); }); + describe('remove', () => { + it('should call isomorphic-git remove with the correct arguments', async () => { + const git = Git.fromAuth({}); + const dir = 'mockdirectory'; + const filepath = 'mockfile/path'; + + await git.remove({ dir, filepath }); + + expect(isomorphic.remove).toHaveBeenCalledWith({ + fs, + dir, + filepath, + }); + }); + }); + describe('deleteRemote', () => { it('should call isomorphic-git with the correct arguments', async () => { const git = Git.fromAuth({}); diff --git a/packages/backend-common/src/scm/git.ts b/packages/backend-common/src/scm/git.ts index 364e1bacd5..e7bad693fe 100644 --- a/packages/backend-common/src/scm/git.ts +++ b/packages/backend-common/src/scm/git.ts @@ -300,6 +300,15 @@ export class Git { return git.readCommit({ fs, dir, oid: sha }); } + /** https://isomorphic-git.org/docs/en/remove */ + async remove(options: { dir: string; filepath: string }): Promise { + const { dir, filepath } = options; + this.config.logger?.info( + `Removing file from git index {dir=${dir},filepath=${filepath}}`, + ); + return git.remove({ fs, dir, filepath }); + } + /** https://isomorphic-git.org/docs/en/resolveRef */ async resolveRef(options: { dir: string; ref: string }): Promise { const { dir, ref } = options;