From 19c18d54f5d7ee073be657e275e6b434510cfdf6 Mon Sep 17 00:00:00 2001 From: ceruleandeep Date: Wed, 11 Dec 2024 19:17:11 +1100 Subject: [PATCH] If cannot get current commit hash for a repo, mark it as up to date --- src/endpoints/extensions.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/endpoints/extensions.js b/src/endpoints/extensions.js index 67b96cc47..b0828757a 100644 --- a/src/endpoints/extensions.js +++ b/src/endpoints/extensions.js @@ -224,12 +224,20 @@ router.post('/version', jsonParser, async (request, response) => { return response.status(404).send(`Directory does not exist at ${extensionPath}`); } + let currentCommitHash; + try { + currentCommitHash = await git.cwd(extensionPath).revparse(['HEAD']); + } catch (error) { + // it is not a git repo, or has no commits yet, or is a bare repo + // not possible to update it, most likely can't get the branch name either + return response.send({ currentBranchName: null, currentCommitHash, isUpToDate: true, remoteUrl: null }); + } + const currentBranch = await git.cwd(extensionPath).branch(); // get only the working branch const currentBranchName = currentBranch.current; await git.cwd(extensionPath).fetch('origin'); - const currentCommitHash = await git.cwd(extensionPath).revparse(['HEAD']); - console.log(currentBranch, currentCommitHash); + console.log(extensionName, currentBranchName, currentCommitHash); const { isUpToDate, remoteUrl } = await checkIfRepoIsUpToDate(extensionPath); return response.send({ currentBranchName, currentCommitHash, isUpToDate, remoteUrl });