From 1e0c759f3d99c7d1cd1ccc0968b6eecd27efce15 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Sat, 4 Jul 2020 12:48:09 +0200
Subject: [PATCH] refactor: remove unnecessary cleanRepo() (#6671)

---
 lib/platform/__snapshots__/index.spec.ts.snap       |  4 ----
 lib/platform/azure/index.spec.ts                    | 10 ----------
 lib/platform/azure/index.ts                         |  6 ------
 lib/platform/bitbucket-server/index.spec.ts         |  4 ----
 lib/platform/bitbucket-server/index.ts              |  7 -------
 lib/platform/bitbucket/index.spec.ts                |  4 ----
 lib/platform/bitbucket/index.ts                     |  8 --------
 lib/platform/common.ts                              |  1 -
 lib/platform/gitea/index.spec.ts                    | 13 -------------
 lib/platform/gitea/index.ts                         |  7 -------
 lib/platform/github/index.ts                        | 11 +----------
 .../gitlab/__snapshots__/index.spec.ts.snap         |  2 --
 lib/platform/gitlab/index.spec.ts                   |  9 ---------
 lib/platform/gitlab/index.ts                        |  7 -------
 lib/util/git/index.spec.ts                          |  1 -
 lib/util/git/index.ts                               | 12 ------------
 lib/workers/repository/index.ts                     |  2 --
 17 files changed, 1 insertion(+), 107 deletions(-)

diff --git a/lib/platform/__snapshots__/index.spec.ts.snap b/lib/platform/__snapshots__/index.spec.ts.snap
index b7d428596e..4c5460a19e 100644
--- a/lib/platform/__snapshots__/index.spec.ts.snap
+++ b/lib/platform/__snapshots__/index.spec.ts.snap
@@ -7,7 +7,6 @@ Array [
   "addAssignees",
   "addReviewers",
   "branchExists",
-  "cleanRepo",
   "commitFiles",
   "createPr",
   "deleteBranch",
@@ -52,7 +51,6 @@ Array [
   "addAssignees",
   "addReviewers",
   "branchExists",
-  "cleanRepo",
   "commitFiles",
   "createPr",
   "deleteBranch",
@@ -97,7 +95,6 @@ Array [
   "addAssignees",
   "addReviewers",
   "branchExists",
-  "cleanRepo",
   "commitFiles",
   "createPr",
   "deleteBranch",
@@ -142,7 +139,6 @@ Array [
   "addAssignees",
   "addReviewers",
   "branchExists",
-  "cleanRepo",
   "commitFiles",
   "createPr",
   "deleteBranch",
diff --git a/lib/platform/azure/index.spec.ts b/lib/platform/azure/index.spec.ts
index 20d9b7d8d4..8646b4be1e 100644
--- a/lib/platform/azure/index.spec.ts
+++ b/lib/platform/azure/index.spec.ts
@@ -35,10 +35,6 @@ describe('platform/azure', () => {
     });
   });
 
-  afterEach(async () => {
-    await azure.cleanRepo();
-  });
-
   // do we need the args?
   // eslint-disable-next-line @typescript-eslint/no-unused-vars
   function getRepos(_token: string, _endpoint: string) {
@@ -170,12 +166,6 @@ describe('platform/azure', () => {
     });
   });
 
-  describe('cleanRepo()', () => {
-    it('exists', async () => {
-      await expect(azure.cleanRepo()).resolves.not.toThrow();
-    });
-  });
-
   describe('initRepo', () => {
     it(`should initialise the config for a repo`, async () => {
       const config = await initRepo({
diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts
index acc2608ec3..855fad559d 100644
--- a/lib/platform/azure/index.ts
+++ b/lib/platform/azure/index.ts
@@ -767,9 +767,3 @@ export /* istanbul ignore next */ async function deleteLabel(
 export function getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]> {
   return Promise.resolve([]);
 }
-
-export function cleanRepo(): Promise<void> {
-  git.cleanRepo();
-  config = {} as any;
-  return Promise.resolve();
-}
diff --git a/lib/platform/bitbucket-server/index.spec.ts b/lib/platform/bitbucket-server/index.spec.ts
index 97415f7103..7b5a659695 100644
--- a/lib/platform/bitbucket-server/index.spec.ts
+++ b/lib/platform/bitbucket-server/index.spec.ts
@@ -197,10 +197,6 @@ describe('platform/bitbucket-server', () => {
         });
       });
 
-      afterEach(async () => {
-        await bitbucket.cleanRepo();
-      });
-
       describe('initPlatform()', () => {
         it('should throw if no endpoint', () => {
           expect.assertions(1);
diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts
index b6df5da0bd..6b389ec284 100644
--- a/lib/platform/bitbucket-server/index.ts
+++ b/lib/platform/bitbucket-server/index.ts
@@ -105,13 +105,6 @@ export async function getRepos(): Promise<string[]> {
   }
 }
 
-export function cleanRepo(): Promise<void> {
-  logger.debug(`cleanRepo()`);
-  git.cleanRepo();
-  config = {} as any;
-  return Promise.resolve();
-}
-
 // Initialize GitLab by getting base branch
 export async function initRepo({
   repository,
diff --git a/lib/platform/bitbucket/index.spec.ts b/lib/platform/bitbucket/index.spec.ts
index cb0946e584..fc81fd4002 100644
--- a/lib/platform/bitbucket/index.spec.ts
+++ b/lib/platform/bitbucket/index.spec.ts
@@ -74,10 +74,6 @@ describe('platform/bitbucket', () => {
     setBaseUrl(baseUrl);
   });
 
-  afterEach(async () => {
-    await bitbucket.cleanRepo();
-  });
-
   async function initRepoMock(
     config?: Partial<RepoParams>,
     repoResp?: any
diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts
index f1bc34f244..fd695abe39 100644
--- a/lib/platform/bitbucket/index.ts
+++ b/lib/platform/bitbucket/index.ts
@@ -870,14 +870,6 @@ export async function mergePr(
   return true;
 }
 
-// Pull Request
-
-export function cleanRepo(): Promise<void> {
-  git.cleanRepo();
-  config = {} as any;
-  return Promise.resolve();
-}
-
 export function getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]> {
   return Promise.resolve([]);
 }
diff --git a/lib/platform/common.ts b/lib/platform/common.ts
index 1238279907..e05e3f7f93 100644
--- a/lib/platform/common.ts
+++ b/lib/platform/common.ts
@@ -190,7 +190,6 @@ export interface Platform {
   getCommitMessages(): Promise<string[]>;
   setBranchPrefix(branchPrefix: string): Promise<void>;
   initRepo(config: RepoParams): Promise<RepoConfig>;
-  cleanRepo(): Promise<void>;
   getPrList(): Promise<Pr[]>;
   getPrFiles(pr: Pr): Promise<string[]>;
   getAllRenovateBranches(branchPrefix: string): Promise<string[]>;
diff --git a/lib/platform/gitea/index.spec.ts b/lib/platform/gitea/index.spec.ts
index 10f801e725..101938707a 100644
--- a/lib/platform/gitea/index.spec.ts
+++ b/lib/platform/gitea/index.spec.ts
@@ -328,19 +328,6 @@ describe('platform/gitea', () => {
     });
   });
 
-  describe('cleanRepo', () => {
-    it('does not throw an error with uninitialized repo', async () => {
-      await gitea.cleanRepo();
-      expect(gitvcs.cleanRepo).toHaveBeenCalledTimes(1);
-    });
-
-    it('propagates call to storage class with initialized repo', async () => {
-      await initFakeRepo();
-      await gitea.cleanRepo();
-      expect(gitvcs.cleanRepo).toHaveBeenCalledTimes(1);
-    });
-  });
-
   describe('setBranchStatus', () => {
     const setBranchStatus = async (bsc?: Partial<BranchStatusConfig>) => {
       await initFakeRepo();
diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts
index ca6cca3f80..6a7c9146b6 100644
--- a/lib/platform/gitea/index.ts
+++ b/lib/platform/gitea/index.ts
@@ -362,12 +362,6 @@ const platform: Platform = {
     }
   },
 
-  cleanRepo(): Promise<void> {
-    git.cleanRepo();
-    config = {} as any;
-    return Promise.resolve();
-  },
-
   async setBranchStatus({
     branchName,
     context,
@@ -913,7 +907,6 @@ export const {
   addAssignees,
   addReviewers,
   branchExists,
-  cleanRepo,
   commitFiles,
   createPr,
   deleteBranch,
diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts
index 773291d293..04bdd79ad3 100644
--- a/lib/platform/github/index.ts
+++ b/lib/platform/github/index.ts
@@ -149,13 +149,6 @@ export async function getRepos(): Promise<string[]> {
   }
 }
 
-export function cleanRepo(): Promise<void> {
-  git.cleanRepo();
-  // In theory most of this isn't necessary. In practice..
-  config = {} as any;
-  return Promise.resolve();
-}
-
 async function getBranchProtection(
   branchName: string
 ): Promise<BranchProtection> {
@@ -208,7 +201,7 @@ export async function initRepo({
 }: RepoParams): Promise<RepoConfig> {
   logger.debug(`initRepo("${repository}")`);
   // config is used by the platform api itself, not necessary for the app layer to know
-  await cleanRepo();
+  config = { localDir, repository } as any;
   // istanbul ignore if
   if (endpoint) {
     // Necessary for Renovate Pro - do not remove
@@ -222,8 +215,6 @@ export async function initRepo({
   });
   config.isGhe = URL.parse(defaults.endpoint).host !== 'api.github.com';
   config.renovateUsername = renovateUsername;
-  config.localDir = localDir;
-  config.repository = repository;
   [config.repositoryOwner, config.repositoryName] = repository.split('/');
   let res;
   try {
diff --git a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap
index 5945db02f7..cc5febdace 100644
--- a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap
+++ b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap
@@ -175,8 +175,6 @@ Array [
 ]
 `;
 
-exports[`platform/gitlab cleanRepo() exists 1`] = `undefined`;
-
 exports[`platform/gitlab commitFiles() sends to gitFs 1`] = `
 Array [
   Object {
diff --git a/lib/platform/gitlab/index.spec.ts b/lib/platform/gitlab/index.spec.ts
index edab97df8e..b109d5f895 100644
--- a/lib/platform/gitlab/index.spec.ts
+++ b/lib/platform/gitlab/index.spec.ts
@@ -45,10 +45,6 @@ describe('platform/gitlab', () => {
     httpMock.setup();
   });
 
-  afterEach(async () => {
-    await gitlab.cleanRepo();
-  });
-
   describe('initPlatform()', () => {
     it(`should throw if no token`, async () => {
       await expect(gitlab.initPlatform({} as any)).rejects.toThrow();
@@ -165,11 +161,6 @@ describe('platform/gitlab', () => {
       expect(httpMock.getTrace()).toMatchSnapshot();
     });
   });
-  describe('cleanRepo()', () => {
-    it('exists', async () => {
-      expect(await gitlab.cleanRepo()).toMatchSnapshot();
-    });
-  });
 
   describe('initRepo', () => {
     it(`should throw error if disabled in renovate.json`, async () => {
diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts
index d91a6eb0e7..93437ee303 100644
--- a/lib/platform/gitlab/index.ts
+++ b/lib/platform/gitlab/index.ts
@@ -138,13 +138,6 @@ function urlEscape(str: string): string {
   return str ? str.replace(/\//g, '%2F') : str;
 }
 
-export function cleanRepo(): Promise<void> {
-  git.cleanRepo();
-  // In theory most of this isn't necessary. In practice..
-  config = {} as any;
-  return Promise.resolve();
-}
-
 // Initialize GitLab by getting base branch
 export async function initRepo({
   repository,
diff --git a/lib/util/git/index.spec.ts b/lib/util/git/index.spec.ts
index 156ac77652..de0a8e3742 100644
--- a/lib/util/git/index.spec.ts
+++ b/lib/util/git/index.spec.ts
@@ -60,7 +60,6 @@ describe('platform/git', () => {
   afterEach(async () => {
     await tmpDir.cleanup();
     await origin.cleanup();
-    git.cleanRepo();
   });
 
   afterAll(async () => {
diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts
index 17e12ede60..92686a7884 100644
--- a/lib/util/git/index.ts
+++ b/lib/util/git/index.ts
@@ -146,19 +146,7 @@ export async function getSubmodules(): Promise<string[]> {
     .filter((_e: string, i: number) => i % 2);
 }
 
-export function isInitialized(): boolean {
-  return !!git;
-}
-
-export function cleanRepo(): void {
-  if (isInitialized()) {
-    // no-op
-  }
-}
-
 export async function initRepo(args: StorageConfig): Promise<void> {
-  cleanRepo();
-
   config = { ...args } as any;
 
   config.branchExists = {};
diff --git a/lib/workers/repository/index.ts b/lib/workers/repository/index.ts
index 64269ebc6a..e3fa6e6559 100644
--- a/lib/workers/repository/index.ts
+++ b/lib/workers/repository/index.ts
@@ -1,7 +1,6 @@
 import fs from 'fs-extra';
 import { RenovateConfig } from '../../config';
 import { logger, setMeta } from '../../logger';
-import { platform } from '../../platform';
 import { deleteLocalFile } from '../../util/fs';
 import { addSplit, getSplits, splitInit } from '../../util/split';
 import handleError from './error';
@@ -51,7 +50,6 @@ export async function renovateRepository(
     const errorRes = await handleError(config, err);
     repoResult = processResult(config, errorRes);
   }
-  await platform.cleanRepo();
   if (config.localDir && !config.persistRepoData) {
     await deleteLocalFile('.');
   }
-- 
GitLab