diff --git a/lib/platform/github/storage.js b/lib/platform/github/storage.js index d0825b5b79a8b992c242e1b0a64c76e4ea9a08ab..d0dbe8ad9c9c3fd4d49d42a82930dcc5d2b11b39 100644 --- a/lib/platform/github/storage.js +++ b/lib/platform/github/storage.js @@ -275,23 +275,23 @@ class Storage { logger.debug( `commitFilesToBranch('${branchName}', files, message, '${parentBranch})'` ); - delete branchFiles[branchName]; - const parentCommit = await getBranchCommit(parentBranch); - const parentTree = await getCommitTree(parentCommit); - const fileBlobs = []; - // Create blobs - for (const file of files) { - const blob = await createBlob(file.contents); - fileBlobs.push({ - name: file.name, - blob, - }); - } - // Create tree - const tree = await createTree(parentTree, fileBlobs); - const commit = await createCommit(parentCommit, tree, message); - const isBranchExisting = await branchExists(branchName); try { + delete branchFiles[branchName]; + const parentCommit = await getBranchCommit(parentBranch); + const parentTree = await getCommitTree(parentCommit); + const fileBlobs = []; + // Create blobs + for (const file of files) { + const blob = await createBlob(file.contents); + fileBlobs.push({ + name: file.name, + blob, + }); + } + // Create tree + const tree = await createTree(parentTree, fileBlobs); + const commit = await createCommit(parentCommit, tree, message); + const isBranchExisting = await branchExists(branchName); if (isBranchExisting) { await updateBranch(branchName, commit); logger.debug({ branch: branchName }, 'Branch updated'); @@ -305,14 +305,9 @@ class Storage { } return 'created'; } catch (err) /* istanbul ignore next */ { - logger.debug({ - files: files.filter( - file => - !file.name.endsWith('package-lock.json') && - !file.name.endsWith('npm-shrinkwrap.json') && - !file.name.endsWith('yarn.lock') - ), - }); + if (err.statusCode === 404) { + throw new Error('repository-changed'); + } throw err; } }