diff --git a/lib/platform/git/storage.ts b/lib/platform/git/storage.ts index 2f8bfe4133bae1e6017747ed7aa66725e0404958..364678e488178d57730aa87bbbf42b7c12720e1f 100644 --- a/lib/platform/git/storage.ts +++ b/lib/platform/git/storage.ts @@ -26,7 +26,6 @@ class Storage { private _git: Git.SimpleGit | undefined; private _cwd: string | undefined; - // istanbul ignore next private async _resetToBranch(branchName: string) { logger.debug(`resetToBranch(${branchName})`); await this._git!.raw(['reset', '--hard']); @@ -35,7 +34,6 @@ class Storage { await this._git!.raw(['clean', '-fd']); } - // istanbul ignore next private async _cleanLocalBranches() { const existingBranches = (await this._git!.raw(['branch'])) .split('\n') @@ -78,16 +76,12 @@ class Storage { } } - // istanbul ignore if - if ( - process.env.NODE_ENV !== 'test' && - /* istanbul ignore next */ (await fs.exists(gitHead)) - ) { + if (await fs.exists(gitHead)) { try { this._git = Git(cwd).silent(true); await this._git.raw(['remote', 'set-url', 'origin', config.url]); const fetchStart = process.hrtime(); - await this._git.fetch([config.url, '--depth=2']); + await this._git.fetch(['--depth=2']); await determineBaseBranch(this._git); await this._resetToBranch(config.baseBranch); await this._cleanLocalBranches(); @@ -98,7 +92,7 @@ class Storage { ) / 10; logger.info({ fetchSeconds }, 'git fetch completed'); clone = false; - } catch (err) { + } catch (err) /* istanbul ignore next */ { logger.error({ err }, 'git fetch error'); } } diff --git a/test/platform/git/__snapshots__/storage.spec.ts.snap b/test/platform/git/__snapshots__/storage.spec.ts.snap index 5837cc8a81a2262af2e9e4eb316abcc5417a0af0..2b46072ad5e724bb73193bff8a1e5972f4ec0c8a 100644 --- a/test/platform/git/__snapshots__/storage.spec.ts.snap +++ b/test/platform/git/__snapshots__/storage.spec.ts.snap @@ -26,6 +26,20 @@ Array [ ] `; +exports[`platform/git/storage initRepo()) should fetch latest 1`] = ` +Array [ + "master message", + "past message", +] +`; + +exports[`platform/git/storage initRepo()) should fetch latest 2`] = ` +Array [ + "past message2", + "master message", +] +`; + exports[`platform/git/storage mergeBranch(branchName) should throw if branch merge throws 1`] = ` [Error: fatal: 'origin/not_found' is not a commit and a branch 'not_found' cannot be created from it ] diff --git a/test/platform/git/storage.spec.ts b/test/platform/git/storage.spec.ts index 6aea43a85bd71f2cd231f730ff4f8a1d0208d515..77911c2e89bd54a6e176910f9b4fbf8bc6f402df 100644 --- a/test/platform/git/storage.spec.ts +++ b/test/platform/git/storage.spec.ts @@ -255,4 +255,34 @@ describe('platform/git/storage', () => { ).toEqual('git@host:some/repo.git'); }); }); + + describe('initRepo())', () => { + it('should fetch latest', async () => { + const repo = Git(base.path).silent(true); + await repo.checkoutBranch('test', 'master'); + await fs.writeFile(base.path + '/test', 'lorem ipsum'); + await repo.add(['test']); + await repo.commit('past message2'); + await repo.checkout('master'); + + expect(await git.branchExists('test')).toBeFalsy(); + + expect(await git.getCommitMessages()).toMatchSnapshot(); + + await git.setBaseBranch('develop'); + + await git.initRepo({ + localDir: tmpDir.path, + url: base.path, + }); + + expect(await git.branchExists('test')).toBeTruthy(); + + await git.setBaseBranch('test'); + + const msg = await git.getCommitMessages(); + expect(msg).toMatchSnapshot(); + expect(msg).toContain('past message2'); + }); + }); });