mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 07:26:26 +00:00
fix(gitfs): reset local branches after fetch
This commit is contained in:
parent
085ce43a47
commit
a4107b44c6
1 changed files with 23 additions and 1 deletions
|
@ -29,6 +29,26 @@ class Storage {
|
||||||
mergeBranch,
|
mergeBranch,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// istanbul ignore next
|
||||||
|
async function resetToBranch(branchName) {
|
||||||
|
await git.raw(['reset', '--hard']);
|
||||||
|
await git.checkout(branchName);
|
||||||
|
await git.raw(['reset', '--hard', 'origin/' + branchName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// istanbul ignore next
|
||||||
|
async function cleanLocalBranches() {
|
||||||
|
const existingBranches = (await git.raw(['branch']))
|
||||||
|
.split('\n')
|
||||||
|
.map(branch => branch.trim())
|
||||||
|
.filter(branch => branch.length)
|
||||||
|
.filter(branch => !branch.startsWith('* '));
|
||||||
|
logger.debug({ existingBranches });
|
||||||
|
for (const branchName of existingBranches) {
|
||||||
|
await deleteLocalBranch(branchName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function initRepo(args) {
|
async function initRepo(args) {
|
||||||
cleanRepo();
|
cleanRepo();
|
||||||
logger.info('Initialising git repository');
|
logger.info('Initialising git repository');
|
||||||
|
@ -55,7 +75,9 @@ class Storage {
|
||||||
await git.raw(['remote', 'set-url', 'origin', config.url]);
|
await git.raw(['remote', 'set-url', 'origin', config.url]);
|
||||||
const fetchStart = process.hrtime();
|
const fetchStart = process.hrtime();
|
||||||
await git.fetch(config.url, ['--depth=2', '--no-single-branch']);
|
await git.fetch(config.url, ['--depth=2', '--no-single-branch']);
|
||||||
await git.raw(['remote', 'prune', 'origin']);
|
await determineBaseBranch();
|
||||||
|
await resetToBranch(config.baseBranch);
|
||||||
|
await cleanLocalBranches();
|
||||||
const fetchSeconds = Math.round(
|
const fetchSeconds = Math.round(
|
||||||
convertHrtime(process.hrtime(fetchStart)).seconds
|
convertHrtime(process.hrtime(fetchStart)).seconds
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue