mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 23:16: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,
|
||||
});
|
||||
|
||||
// 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) {
|
||||
cleanRepo();
|
||||
logger.info('Initialising git repository');
|
||||
|
@ -55,7 +75,9 @@ class Storage {
|
|||
await git.raw(['remote', 'set-url', 'origin', config.url]);
|
||||
const fetchStart = process.hrtime();
|
||||
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(
|
||||
convertHrtime(process.hrtime(fetchStart)).seconds
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue