Skip to content
Snippets Groups Projects
Commit affc0116 authored by Michael Kriese's avatar Michael Kriese Committed by Rhys Arkins
Browse files

fix(gitFs): fix fetch args (#3723)

fix(gitfs): fix wrong fetch arguments
parent 0d369ad8
Branches
Tags
No related merge requests found
......@@ -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');
}
}
......
......@@ -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
]
......
......@@ -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');
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment