backend-common: wrap branch command

Signed-off-by: Magnus Persson <magnus.persson@fortnox.se>
This commit is contained in:
Magnus Persson
2022-09-13 10:21:50 +02:00
parent 4f75b45f58
commit 709f468330
4 changed files with 30 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
The `branch` command has been added to the `Git` isomorphic-git wrapper.
+2
View File
@@ -342,6 +342,8 @@ export class Git {
force?: boolean;
}): Promise<void>;
// (undocumented)
branch(options: { dir: string; ref: string }): Promise<void>;
// (undocumented)
checkout(options: { dir: string; ref: string }): Promise<void>;
clone(options: {
url: string;
@@ -95,6 +95,22 @@ describe('Git', () => {
});
});
describe('branch', () => {
it('should call isomorphic-git with the correct arguments', async () => {
const git = Git.fromAuth({});
const dir = 'mockdirectory';
const ref = 'master';
await git.branch({ dir, ref });
expect(isomorphic.branch).toHaveBeenCalledWith({
fs,
dir,
ref,
});
});
});
describe('commit', () => {
it('should call isomorphic-git with the correct arguments', async () => {
const git = Git.fromAuth({});
+7
View File
@@ -94,6 +94,13 @@ export class Git {
return git.checkout({ fs, dir, ref });
}
async branch(options: { dir: string; ref: string }): Promise<void> {
const { dir, ref } = options;
this.config.logger?.info(`Creating branch {dir=${dir},ref=${ref}`);
return git.branch({ fs, dir, ref });
}
async commit(options: {
dir: string;
message: string;