diff --git a/lib/util/git/index.spec.ts b/lib/util/git/index.spec.ts index b7607533fbe93814eeb364f1c35bf6b4c3aaee7a..e06e7fb40fe4e1bb1c442982aea678459506c3d3 100644 --- a/lib/util/git/index.spec.ts +++ b/lib/util/git/index.spec.ts @@ -1084,10 +1084,10 @@ describe('util/git/index', () => { it('creates custom section for renovate ref', async () => { const commit = git.getBranchCommit('develop')!; - await git.pushCommitToRenovateRef(commit, 'bar/baz', 'foo'); + await git.pushCommitToRenovateRef(commit, 'bar/baz'); const renovateRefs = await lsRenovateRefs(); - expect(renovateRefs).toContain('refs/renovate/foo/bar/baz'); + expect(renovateRefs).toContain('refs/renovate/branches/bar/baz'); }); it('clears pushed Renovate refs', async () => { @@ -1104,11 +1104,16 @@ describe('util/git/index', () => { it('clears remote Renovate refs', async () => { const commit = git.getBranchCommit('develop')!; const tmpGit = Git(tmpDir.path); - await tmpGit.raw(['update-ref', 'refs/renovate/aaa', commit]); - await tmpGit.raw(['push', '--force', 'origin', 'refs/renovate/aaa']); + await tmpGit.raw(['update-ref', 'refs/renovate/branches/aaa', commit]); + await tmpGit.raw([ + 'push', + '--force', + 'origin', + 'refs/renovate/branches/aaa', + ]); await git.pushCommitToRenovateRef(commit, 'bbb'); - await git.pushCommitToRenovateRef(commit, 'ccc', 'branches'); + await git.pushCommitToRenovateRef(commit, 'ccc'); const pushSpy = jest.spyOn(SimpleGit.prototype, 'push'); diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index cabe042fb38fe0c6b6295cd109fe3b587137b550..987ef3119047bf36457462b396840313f2d757a0 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -1248,9 +1248,8 @@ let remoteRefsExist = false; export async function pushCommitToRenovateRef( commitSha: string, refName: string, - section = 'branches', ): Promise<void> { - const fullRefName = `refs/renovate/${section}/${refName}`; + const fullRefName = `refs/renovate/branches/${refName}`; await git.raw(['update-ref', fullRefName, commitSha]); await git.push(['--force', 'origin', fullRefName]); remoteRefsExist = true; @@ -1258,75 +1257,67 @@ export async function pushCommitToRenovateRef( /** * - * Removes all remote "refs/renovate/*" refs in two steps: + * Removes all remote "refs/renovate/branches/*" refs in two steps: * * Step 1: list refs * - * $ git ls-remote origin "refs/renovate/*" + * $ git ls-remote origin "refs/renovate/branches/*" * - * > cca38e9ea6d10946bdb2d0ca5a52c205783897aa refs/renovate/foo - * > 29ac154936c880068994e17eb7f12da7fdca70e5 refs/renovate/bar - * > 3fafaddc339894b6d4f97595940fd91af71d0355 refs/renovate/baz + * > cca38e9ea6d10946bdb2d0ca5a52c205783897aa refs/renovate/branches/foo + * > 29ac154936c880068994e17eb7f12da7fdca70e5 refs/renovate/branches/bar + * > 3fafaddc339894b6d4f97595940fd91af71d0355 refs/renovate/branches/baz * > ... * * Step 2: * - * $ git push --delete origin refs/renovate/foo refs/renovate/bar refs/renovate/baz + * $ git push --delete origin refs/renovate/branches/foo refs/renovate/branches/bar refs/renovate/branches/baz * * If Step 2 fails because the repo doesn't allow bulk changes, we'll remove them one by one instead: * - * $ git push --delete origin refs/renovate/foo - * $ git push --delete origin refs/renovate/bar - * $ git push --delete origin refs/renovate/baz + * $ git push --delete origin refs/renovate/branches/foo + * $ git push --delete origin refs/renovate/branches/bar + * $ git push --delete origin refs/renovate/branches/baz */ export async function clearRenovateRefs(): Promise<void> { if (!gitInitialized || !remoteRefsExist) { return; } - logger.debug(`Cleaning up Renovate refs: refs/renovate/*`); + logger.debug(`Cleaning up Renovate refs: refs/renovate/branches/*`); const renovateRefs: string[] = []; - const obsoleteRefs: string[] = []; try { - const rawOutput = await git.listRemote([config.url, 'refs/renovate/*']); + const rawOutput = await git.listRemote([ + config.url, + 'refs/renovate/branches/*', + ]); const refs = rawOutput .split(newlineRegex) .map((line) => line.replace(regEx(/[0-9a-f]+\s+/i), '').trim()) - .filter((line) => line.startsWith('refs/renovate/')); + .filter((line) => line.startsWith('refs/renovate/branches/')); renovateRefs.push(...refs); } catch (err) /* istanbul ignore next */ { logger.warn({ err }, `Renovate refs cleanup error`); } - const nonSectionedRefs = renovateRefs.filter((ref) => { - return ref.split('/').length === 3; - }); - obsoleteRefs.push(...nonSectionedRefs); - - const renovateBranchRefs = renovateRefs.filter((ref) => - ref.startsWith('refs/renovate/branches/'), - ); - obsoleteRefs.push(...renovateBranchRefs); - - if (obsoleteRefs.length) { + if (renovateRefs.length) { try { - const pushOpts = ['--delete', 'origin', ...obsoleteRefs]; + const pushOpts = ['--delete', 'origin', ...renovateRefs]; await git.push(pushOpts); } catch (err) { /* istanbul ignore else */ if (bulkChangesDisallowed(err)) { - for (const ref of obsoleteRefs) { + for (const ref of renovateRefs) { try { const pushOpts = ['--delete', 'origin', ref]; await git.push(pushOpts); } catch (err) /* istanbul ignore next */ { - logger.debug({ err }, 'Error deleting obsolete refs'); + logger.debug({ err }, 'Error deleting "refs/renovate/branches/*"'); break; } } } else { - logger.warn({ err }, 'Error deleting obsolete refs'); + logger.warn({ err }, 'Error deleting "refs/renovate/branches/*"'); } } }