From 3b24eaecbcbc48e635725ff3dfb6722546241ec4 Mon Sep 17 00:00:00 2001 From: "manuel.falcon" Date: Sat, 23 Dec 2023 11:28:51 +0100 Subject: [PATCH 1/3] 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; From 1c9567d7350617e22fdeba07a565fd1de2ea38f4 Mon Sep 17 00:00:00 2001 From: "manuel.falcon" Date: Sat, 23 Dec 2023 11:28:51 +0100 Subject: [PATCH 2/3] Adding support for removing file from git index Signed-off-by: manuel.falcon --- packages/backend-common/api-report.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend-common/api-report.md b/packages/backend-common/api-report.md index e7d89c2aa5..2d0eb84619 100644 --- a/packages/backend-common/api-report.md +++ b/packages/backend-common/api-report.md @@ -417,6 +417,7 @@ export class Git { force?: boolean; }): Promise; readCommit(options: { dir: string; sha: string }): Promise; + remove(options: { dir: string; filepath: string }): Promise; resolveRef(options: { dir: string; ref: string }): Promise; } From 4c03e905d284ff795746a615c9f3d1af610225d0 Mon Sep 17 00:00:00 2001 From: "manuel.falcon" Date: Fri, 5 Jan 2024 13:15:57 +0100 Subject: [PATCH 3/3] Changing minor for patch as sugested in PR Signed-off-by: manuel.falcon --- .changeset/brave-shirts-hang.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/brave-shirts-hang.md b/.changeset/brave-shirts-hang.md index 07aeb514da..4fa7e4ef77 100644 --- a/.changeset/brave-shirts-hang.md +++ b/.changeset/brave-shirts-hang.md @@ -1,5 +1,5 @@ --- -'@backstage/backend-common': minor +'@backstage/backend-common': patch --- Adding support for removing file from git index