From 701b4ee526a9b27dc7ded06f3609a5509625cbf7 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Fri, 3 May 2019 00:08:22 +0200
Subject: [PATCH] fix(gomod): tidy again after vendoring

---
 lib/manager/gomod/artifacts.js | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/lib/manager/gomod/artifacts.js b/lib/manager/gomod/artifacts.js
index b5d3d05f7b..cfdbe02b2a 100644
--- a/lib/manager/gomod/artifacts.js
+++ b/lib/manager/gomod/artifacts.js
@@ -114,8 +114,8 @@ async function getArtifacts(
         duration = process.hrtime(startTime);
         seconds = Math.round(duration[0] + duration[1] / 1e9);
         logger.info(
-          { seconds, type: 'go.sum', stdout, stderr },
-          'Tidied lockfile'
+          { seconds, stdout, stderr },
+          'Tidied Go Modules after update'
         );
       } else {
         logger.warn(
@@ -163,6 +163,27 @@ async function getArtifacts(
         duration = process.hrtime(startTime);
         seconds = Math.round(duration[0] + duration[1] / 1e9);
         logger.info({ seconds, stdout, stderr }, 'Vendored modules');
+        if (
+          config.postUpdateOptions &&
+          config.postUpdateOptions.includes('gomodTidy')
+        ) {
+          args = 'mod tidy';
+          if (cmd.includes('.insteadOf')) {
+            args += '"';
+          }
+          logger.debug({ cmd, args }, 'go mod tidy command');
+          ({ stdout, stderr } = await exec(`${cmd} ${args}`, {
+            cwd,
+            shell: true,
+            env,
+          }));
+          duration = process.hrtime(startTime);
+          seconds = Math.round(duration[0] + duration[1] / 1e9);
+          logger.info(
+            { seconds, stdout, stderr },
+            'Tidied Go Modules after vendoring'
+          );
+        }
         const status = await platform.getRepoStatus();
         for (const f of status.modified.concat(status.not_added)) {
           if (f.startsWith(vendorDir)) {
-- 
GitLab