Only fetch if the repo is shallow (to avoid unnecessary errors) (#215)

* Only fetch if the repo is shallow (to avoid unnecessary errors)

* Update src/model/versioning.test.js
This commit is contained in:
David Finol 2021-02-12 23:22:23 -06:00 committed by GitHub
parent b0df698630
commit faefe2f8d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@ -119,7 +119,9 @@ export default class Versioning {
* @See: https://semver.org/
*/
static async generateSemanticVersion() {
await this.fetch();
if (await this.isShallow()) {
await this.fetch();
}
await this.logDiff();
@ -203,6 +205,15 @@ export default class Versioning {
}
}
/**
* Returns whether the repository is shallow.
*/
static async isShallow() {
const output = await this.git(['rev-parse', '--is-shallow-repository']);
return output === 'true';
}
/**
* Retrieves refs from the configured remote.
*

View File

@ -104,6 +104,7 @@ describe('Versioning', () => {
it('calls git diff', async () => {
// allowDirtyBuild: true
jest.spyOn(core, 'getInput').mockReturnValue('true');
jest.spyOn(Versioning, 'isShallow').mockResolvedValue(true);
jest.spyOn(Versioning, 'isDirty').mockResolvedValue(false);
jest.spyOn(Versioning, 'fetch').mockResolvedValue(undefined);
jest.spyOn(Versioning, 'hasAnyVersionTags').mockResolvedValue(true);
@ -237,6 +238,20 @@ describe('Versioning', () => {
});
});
describe('isShallow', () => {
it('returns true when the repo is shallow', async () => {
const runOutput = 'true';
jest.spyOn(System, 'run').mockResolvedValue(runOutput);
await expect(Versioning.isShallow()).resolves.toStrictEqual(true);
});
it('returns false when the repo is not shallow', async () => {
const runOutput = 'false';
jest.spyOn(System, 'run').mockResolvedValue(runOutput);
await expect(Versioning.isShallow()).resolves.toStrictEqual(false);
});
});
describe('fetch', () => {
it('awaits the command', async () => {
jest.spyOn(core, 'warning').mockImplementation(() => {});