Select Git revision
storage.spec.ts
storage.spec.ts 12.82 KiB
import fs from 'fs-extra';
import Git from 'simple-git/promise';
import tmp from 'tmp-promise';
import GitStorage from './storage';
describe('platform/git/storage', () => {
jest.setTimeout(15000);
const git = new GitStorage();
const masterCommitDate = new Date();
masterCommitDate.setMilliseconds(0);
let base: tmp.DirectoryResult;
let origin: tmp.DirectoryResult;
beforeAll(async () => {
base = await tmp.dir({ unsafeCleanup: true });
const repo = Git(base.path).silent(true);
await repo.init();
await repo.addConfig('user.email', 'Jest@example.com');
await repo.addConfig('user.name', 'Jest');
await fs.writeFile(base.path + '/past_file', 'past');
await repo.add(['past_file']);
await repo.commit('past message');
await repo.checkoutBranch('renovate/past_branch', 'master');
await repo.checkoutBranch('develop', 'master');
await repo.checkout('master');
await fs.writeFile(base.path + '/master_file', 'master');
await fs.writeFile(base.path + '/file_to_delete', 'bye');
await repo.add(['master_file', 'file_to_delete']);
await repo.commit('master message', [
'--date=' + masterCommitDate.toISOString(),
]);
await repo.checkoutBranch('renovate/future_branch', 'master');
await fs.writeFile(base.path + '/future_file', 'future');
await repo.add(['future_file']);
await repo.commit('future message');
await repo.checkout('master');
});
let tmpDir: tmp.DirectoryResult;
beforeEach(async () => {
origin = await tmp.dir({ unsafeCleanup: true });
const repo = Git(origin.path);
await repo.clone(base.path, '.', ['--bare']);
tmpDir = await tmp.dir({ unsafeCleanup: true });
global.gitAuthor = {
name: 'test',
email: 'test@example.com',
};
await git.initRepo({
localDir: tmpDir.path,
url: origin.path,
extraCloneOpts: {
'--config': 'extra.clone.config=test-extra-config-value',
},
});
});
afterEach(async () => {
await tmpDir.cleanup();
await origin.cleanup();
git.cleanRepo();
});
afterAll(async () => {
await base.cleanup();