mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-04 12:25:19 -04:00
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:
parent
b0df698630
commit
faefe2f8d7
File diff suppressed because one or more lines are too long
@ -119,7 +119,9 @@ export default class Versioning {
|
||||
* @See: https://semver.org/
|
||||
*/
|
||||
static async generateSemanticVersion() {
|
||||
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.
|
||||
*
|
||||
|
@ -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(() => {});
|
||||
|
Loading…
Reference in New Issue
Block a user