Merge pull request #22012 from manuelfalcon/master

Adding support for removing file from git index
This commit is contained in:
Ben Lambert
2024-01-10 15:59:35 +01:00
committed by GitHub
4 changed files with 31 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
Adding support for removing file from git index
+1
View File
@@ -417,6 +417,7 @@ export class Git {
force?: boolean;
}): Promise<PushResult>;
readCommit(options: { dir: string; sha: string }): Promise<ReadCommitResult>;
remove(options: { dir: string; filepath: string }): Promise<void>;
resolveRef(options: { dir: string; ref: string }): Promise<string>;
}
@@ -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({});
+9
View File
@@ -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<void> {
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<string> {
const { dir, ref } = options;