From b6eca211109825e7faf44748cd743d955cda397d Mon Sep 17 00:00:00 2001
From: Ivan Trubach <mr.trubach@icloud.com>
Date: Wed, 18 Dec 2019 22:31:08 +0300
Subject: [PATCH] Fix VERSION.cache being reused in test build

---
 src/installer.ts | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/installer.ts b/src/installer.ts
index bb18d7a..ce4d1bd 100644
--- a/src/installer.ts
+++ b/src/installer.ts
@@ -99,7 +99,9 @@ async function acquireGo(version: string, gotipRef: string, bootstrapGo: string)
         if (!workTree) {
           // We found gotip.git in cache, but not the work tree.
           //
-          workTree = path.join(extPath, filename);
+          // Also append commit hash to prevent conflicts with
+          // other checkouts.
+          workTree = path.join(extPath, filename, commitHash);
           // Work tree must exist, otherwise Git will complain
           // that “this operation must be run in a work tree”.
           await io.mkdirP(workTree);
@@ -122,6 +124,10 @@ async function acquireGo(version: string, gotipRef: string, bootstrapGo: string)
         const env = {
           'GOROOT_BOOTSTRAP': bootstrap,
           ...process.env,
+          // Tell Git where to look for the repo. Git will be invoked
+          // by cmd/dist to find Go version and write VERSION file.
+          'GIT_DIR': gitDir,
+          'GIT_WORK_TREE': workTree,
           // Note that while we disable Cgo for tip builds, it does
           // not disable Cgo entirely. Moreover, we override this
           // value in setGoEnvironmentVariables with whatever the