From 7a8f9a236cd1a70aa66fc4628edceb7ff21c9a2d Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 8 Aug 2024 17:20:01 +0100 Subject: [PATCH] Ensure examples clone is up to date --- src/utils/download.mts | 16 +++++++++------- src/utils/examplesUtil.mts | 23 ++++++++++++++++++++--- src/utils/gitUtil.mts | 2 +- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/utils/download.mts b/src/utils/download.mts index 7955491..cb1f749 100644 --- a/src/utils/download.mts +++ b/src/utils/download.mts @@ -768,13 +768,15 @@ export async function downloadAndInstallOpenOCD( }.${assetExt}`; const extraCallback = (): void => { - // on darwin and linux platforms create windows compatible alias - // so confiuration works on all platforms - symlinkSync( - join(targetDirectory, "openocd"), - join(targetDirectory, "openocd.exe"), - "file" - ); + if (process.platform !== "win32") { + // on darwin and linux platforms create windows compatible alias + // so confiuration works on all platforms + symlinkSync( + join(targetDirectory, "openocd"), + join(targetDirectory, "openocd.exe"), + "file" + ); + } }; return downloadAndInstallGithubAsset( diff --git a/src/utils/examplesUtil.mts b/src/utils/examplesUtil.mts index 167f453..183dcb2 100644 --- a/src/utils/examplesUtil.mts +++ b/src/utils/examplesUtil.mts @@ -1,8 +1,8 @@ import { join as joinPosix } from "path/posix"; import Logger from "../logger.mjs"; -import { existsSync, readFileSync } from "fs"; +import { existsSync, readFileSync, rmSync } from "fs"; import { homedir } from "os"; -import { getGit, sparseCheckout, sparseCloneRepository } from "./gitUtil.mjs"; +import { getGit, sparseCheckout, sparseCloneRepository, execAsync } from "./gitUtil.mjs"; import Settings from "../settings.mjs"; import { checkForInstallationRequirements } from "./requirementsUtil.mjs"; import { cp } from "fs/promises"; @@ -16,6 +16,10 @@ const EXAMPLES_REPOSITORY_URL = const EXAMPLES_JSON_URL = "https://raspberrypi.github.io/pico-vscode/" + `${CURRENT_DATA_VERSION}/examples.json`; +const EXAMPLES_GITREF = + "7fe60d6b4027771e45d97f207532c41b1d8c5418"; +const EXAMPLES_TAG = + "sdk-2.0.0"; export interface Example { path: string; @@ -134,10 +138,23 @@ export async function setupExample( const gitPath = await getGit(settings); + if (existsSync(examplesRepoPath)) { + let ref = await execAsync( + `cd "${examplesRepoPath}" && ${ + process.env.ComSpec === "powershell.exe" ? "&" : "" + }"${gitPath}" rev-parse HEAD` + ); + Logger.log(`Examples git ref is ${ref.stdout}\n`); + if (ref.stdout.trim() !== EXAMPLES_GITREF) { + Logger.log(`Removing old examples repo\n`); + rmSync(examplesRepoPath, { recursive: true, force: true }); + } + } + if (!existsSync(examplesRepoPath)) { const result = await sparseCloneRepository( EXAMPLES_REPOSITORY_URL, - "master", + EXAMPLES_TAG, examplesRepoPath, gitPath ); diff --git a/src/utils/gitUtil.mts b/src/utils/gitUtil.mts index 18b3b1b..230e40c 100644 --- a/src/utils/gitUtil.mts +++ b/src/utils/gitUtil.mts @@ -8,7 +8,7 @@ import { homedir } from "os"; import which from "which"; import { window } from "vscode"; -const execAsync = promisify(exec); +export const execAsync = promisify(exec); /** * Get installed version of git, and install it if it isn't already