From 6606e4117b79e9d062221ec3a27599945ccaf8c7 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Fri, 3 Sep 2021 09:23:00 +0200 Subject: [PATCH] refactor(git): log deleted files (#11561) --- lib/util/git/index.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index 87443a761f..707e15b3fd 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -740,11 +740,20 @@ export async function commitFiles({ await git.raw(['clean', '-fd']); await git.checkout(['-B', branchName, 'origin/' + config.currentBranch]); const fileNames: string[] = []; - const deleted: string[] = []; + const deletedFiles: string[] = []; + const ignoredFiles: string[] = []; for (const file of files) { // istanbul ignore if if (file.name === '|delete|') { - deleted.push(file.contents as string); + const fileName = file.contents as string; + try { + await git.rm([fileName]); + deletedFiles.push(fileName); + } catch (err) /* istanbul ignore next */ { + checkForPlatformFailure(err); + logger.warn({ err, fileName }, 'Cannot delete file'); + ignoredFiles.push(fileName); + } } else if (await isDirectory(join(localDir, file.name))) { fileNames.push(file.name); await gitAdd(file.name); @@ -767,16 +776,6 @@ export async function commitFiles({ if (fileNames.length) { await gitAdd(fileNames); } - if (deleted.length) { - for (const f of deleted) { - try { - await git.rm([f]); - } catch (err) /* istanbul ignore next */ { - checkForPlatformFailure(err); - logger.debug({ err }, 'Cannot delete ' + f); - } - } - } const commitOptions: Options = {}; if (getNoVerify().includes(GitNoVerifyOption.Commit)) { @@ -793,7 +792,10 @@ export async function commitFiles({ logger.warn({ commitRes }, 'Detected empty commit - aborting git push'); return null; } - logger.debug({ result: commitRes }, `git commit`); + logger.debug( + { deletedFiles, ignoredFiles, result: commitRes }, + `git commit` + ); const commit = commitRes?.commit || 'unknown'; if (!force && !(await hasDiff(`origin/${branchName}`))) { logger.debug(