Add force options to git wrapper
Signed-off-by: Niya Ma <niyama12321@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-common': patch
|
||||
---
|
||||
|
||||
Add force push, force addRemote, and deleteRemote to git wrapper. **_All parameters added are optional_**
|
||||
@@ -48,14 +48,32 @@ describe('Git', () => {
|
||||
const dir = 'mockdirectory';
|
||||
const remote = 'origin';
|
||||
const url = 'git@github.com/something/sads';
|
||||
const force = true;
|
||||
|
||||
await git.addRemote({ dir, remote, url });
|
||||
await git.addRemote({ dir, remote, url, force });
|
||||
|
||||
expect(isomorphic.addRemote).toHaveBeenCalledWith({
|
||||
fs,
|
||||
dir,
|
||||
remote,
|
||||
url,
|
||||
force,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteRemote', () => {
|
||||
it('should call isomorphic-git with the correct arguments', async () => {
|
||||
const git = Git.fromAuth({});
|
||||
const dir = 'mockdirectory';
|
||||
const remote = 'origin';
|
||||
|
||||
await git.deleteRemote({ dir, remote });
|
||||
|
||||
expect(isomorphic.deleteRemote).toHaveBeenCalledWith({
|
||||
fs,
|
||||
dir,
|
||||
remote,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -295,14 +313,18 @@ describe('Git', () => {
|
||||
password: 'hunter2',
|
||||
};
|
||||
const git = Git.fromAuth(auth);
|
||||
const remoteRef = 'master';
|
||||
const force = true;
|
||||
|
||||
await git.push({ dir, remote });
|
||||
await git.push({ dir, remote, remoteRef, force });
|
||||
|
||||
expect(isomorphic.push).toHaveBeenCalledWith({
|
||||
fs,
|
||||
http,
|
||||
remote,
|
||||
dir,
|
||||
remoteRef,
|
||||
force,
|
||||
onProgress: expect.any(Function),
|
||||
headers: {
|
||||
'user-agent': 'git/@isomorphic-git',
|
||||
@@ -318,8 +340,10 @@ describe('Git', () => {
|
||||
password: 'hunter2',
|
||||
};
|
||||
const git = Git.fromAuth(auth);
|
||||
const remoteRef = 'master';
|
||||
const force = true;
|
||||
|
||||
await git.push({ remote, dir });
|
||||
await git.push({ remote, dir, remoteRef, force });
|
||||
|
||||
const { onAuth } = (
|
||||
isomorphic.push as unknown as jest.Mock<typeof isomorphic['push']>
|
||||
@@ -336,6 +360,8 @@ describe('Git', () => {
|
||||
password: 'hunter2',
|
||||
};
|
||||
const git = Git.fromAuth(auth);
|
||||
const remoteRef = 'master';
|
||||
const force = true;
|
||||
|
||||
(isomorphic.push as jest.Mock).mockImplementation(() => {
|
||||
const error: Error & { data?: unknown } = new Error('mock error');
|
||||
@@ -344,7 +370,7 @@ describe('Git', () => {
|
||||
throw error;
|
||||
});
|
||||
|
||||
await expect(git.push({ remote, dir })).rejects.toThrow(
|
||||
await expect(git.push({ remote, dir, remoteRef, force })).rejects.toThrow(
|
||||
'more information here',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -58,12 +58,19 @@ export class Git {
|
||||
dir: string;
|
||||
remote: string;
|
||||
url: string;
|
||||
force?: boolean;
|
||||
}): Promise<void> {
|
||||
const { dir, url, remote } = options;
|
||||
const { dir, url, remote, force } = options;
|
||||
this.config.logger?.info(
|
||||
`Creating new remote {dir=${dir},remote=${remote},url=${url}}`,
|
||||
);
|
||||
return git.addRemote({ fs, dir, remote, url });
|
||||
return git.addRemote({ fs, dir, remote, url, force });
|
||||
}
|
||||
|
||||
async deleteRemote(options: { dir: string; remote: string }): Promise<void> {
|
||||
const { dir, remote } = options;
|
||||
this.config.logger?.info(`Deleting remote {dir=${dir},remote=${remote}}`);
|
||||
return git.deleteRemote({ fs, dir, remote });
|
||||
}
|
||||
|
||||
async commit(options: {
|
||||
@@ -190,8 +197,13 @@ export class Git {
|
||||
});
|
||||
}
|
||||
|
||||
async push(options: { dir: string; remote: string }) {
|
||||
const { dir, remote } = options;
|
||||
async push(options: {
|
||||
dir: string;
|
||||
remote: string;
|
||||
remoteRef?: string;
|
||||
force?: boolean;
|
||||
}) {
|
||||
const { dir, remote, remoteRef, force } = options;
|
||||
this.config.logger?.info(
|
||||
`Pushing directory to remote {dir=${dir},remote=${remote}}`,
|
||||
);
|
||||
@@ -201,6 +213,8 @@ export class Git {
|
||||
dir,
|
||||
http,
|
||||
onProgress: this.onProgressHandler(),
|
||||
remoteRef,
|
||||
force,
|
||||
headers: {
|
||||
'user-agent': 'git/@isomorphic-git',
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user