Skip to content

Commit 7ed07b1

Browse files
authored
fix(git): optimize syncGit (renovatebot#35349)
1 parent a24d3d1 commit 7ed07b1

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

lib/util/git/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ async function cleanLocalBranches(): Promise<void> {
269269
const existingBranches = (await git.raw(['branch']))
270270
.split(newlineRegex)
271271
.map((branch) => branch.trim())
272-
.filter((branch) => branch.length)
273-
.filter((branch) => !branch.startsWith('* '));
272+
.filter((branch) => branch.length > 0 && !branch.startsWith('* '));
274273
logger.debug({ existingBranches });
275274
for (const branchName of existingBranches) {
276275
await deleteLocalBranch(branchName);
@@ -405,15 +404,12 @@ export async function syncGit(): Promise<void> {
405404
if (await fs.pathExists(gitHead)) {
406405
try {
407406
await git.raw(['remote', 'set-url', 'origin', config.url]);
408-
await resetToBranch(await getDefaultBranch(git));
409407
const fetchStart = Date.now();
410-
await gitRetry(() => git.pull());
411-
await gitRetry(() => git.fetch());
408+
await gitRetry(() => git.fetch(['--prune', 'origin']));
412409
config.currentBranch =
413410
config.currentBranch || (await getDefaultBranch(git));
414411
await resetToBranch(config.currentBranch);
415412
await cleanLocalBranches();
416-
await gitRetry(() => git.raw(['remote', 'prune', 'origin']));
417413
const durationMs = Math.round(Date.now() - fetchStart);
418414
logger.info({ durationMs }, 'git fetch completed');
419415
clone = false;

0 commit comments

Comments
 (0)