diff --git a/lib/platform/github/__snapshots__/index.spec.ts.snap b/lib/platform/github/__snapshots__/index.spec.ts.snap index 41eee3b17cece0125ff47f026ba560a1ab179927..d51b08c1e0d9d75d3b655d51039cafef8f5cbe03 100644 --- a/lib/platform/github/__snapshots__/index.spec.ts.snap +++ b/lib/platform/github/__snapshots__/index.spec.ts.snap @@ -4845,12 +4845,12 @@ Array [ "url": "https://api.github.com/repos/forked/repo/git/refs", }, Object { - "body": "{\\"default_branch\\":\\"master\\"}", + "body": "{\\"name\\":\\"repo\\",\\"default_branch\\":\\"master\\"}", "headers": Object { "accept": "application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": "27", + "content-length": "41", "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index c4b742b2c868c5a10cce5e93e5b978b45553f3e8..1533d7ab2870ee9d6feaa9026b02273e96d0f0f2 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -328,14 +328,26 @@ export async function initRepo({ }); logger.debug('Created new default branch in fork'); } catch (err) /* istanbul ignore next */ { - logger.warn({ err }, 'Could not create parent defaultBranch in fork'); + if (err.response?.body?.message === 'Reference already exists') { + logger.debug( + `Branch ${config.defaultBranch} already exists in the fork` + ); + } else { + logger.warn( + { err }, + 'Could not create parent defaultBranch in fork' + ); + } } logger.debug( `Setting ${config.defaultBranch} as default branch for ${config.repository}` ); try { await githubApi.patchJson(`repos/${config.repository}`, { - body: { default_branch: config.defaultBranch }, + body: { + name: config.repository.split('/')[1], + default_branch: config.defaultBranch, + }, }); logger.debug('Successfully changed default branch for fork'); } catch (err) /* istanbul ignore next */ {