From 3c6bbc388ee36024bc037fff79e1d4f279d25045 Mon Sep 17 00:00:00 2001 From: Tyler Smalley Date: Wed, 1 May 2019 11:25:11 -0700 Subject: [PATCH] Revert "[Code] Use Git WorkTree to create workspace for LSP (#35398)" (#35885) This reverts commit f69fd3833e19212123c3f4cb2e8c950550e43b64. --- x-pack/package.json | 2 +- .../code/server/lsp/workspace_handler.ts | 36 +++---------------- yarn.lock | 8 ++--- 3 files changed, 10 insertions(+), 36 deletions(-) diff --git a/x-pack/package.json b/x-pack/package.json index da6c0ea4f9842..cf87ccb79b98f 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -170,7 +170,7 @@ "@elastic/javascript-typescript-langserver": "^0.1.23", "@elastic/lsp-extension": "^0.1.1", "@elastic/node-crypto": "0.1.2", - "@elastic/nodegit": "0.25.0-alpha.14", + "@elastic/nodegit": "0.25.0-alpha.12", "@elastic/numeral": "2.3.3", "@kbn/babel-preset": "1.0.0", "@kbn/elastic-idx": "1.0.0", diff --git a/x-pack/plugins/code/server/lsp/workspace_handler.ts b/x-pack/plugins/code/server/lsp/workspace_handler.ts index 6405680dc5f2b..24d55034cdc14 100644 --- a/x-pack/plugins/code/server/lsp/workspace_handler.ts +++ b/x-pack/plugins/code/server/lsp/workspace_handler.ts @@ -4,15 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - Commit, - Error as GitError, - Repository, - Reset, - TreeEntry, - // @ts-ignore - Worktree, -} from '@elastic/nodegit'; +import { Clone, Commit, Error as GitError, Repository, Reset, TreeEntry } from '@elastic/nodegit'; import Boom from 'boom'; import del from 'del'; import fs from 'fs'; @@ -361,10 +353,6 @@ export class WorkspaceHandler { } } - private workspaceWorktreeBranchName(repoName: string): string { - return `workspace-${repoName}`; - } - private async updateWorkspace( repositoryUri: string, revision: string, @@ -374,13 +362,8 @@ export class WorkspaceHandler { const workspaceRepo = await Repository.open(workspaceDir); const workspaceHead = await workspaceRepo.getHeadCommit(); if (workspaceHead.sha() !== targetCommit.sha()) { - const commit = await workspaceRepo.getCommit(targetCommit.sha()); - this.log.info(`Checkout workspace ${workspaceDir} to ${targetCommit.sha()}`); - // @ts-ignore - const result = await Reset.reset(workspaceRepo, commit, Reset.TYPE.HARD, {}); - if (result !== undefined && result !== GitError.CODE.OK) { - throw Boom.internal(`Reset workspace to commit ${targetCommit.sha()} failed.`); - } + this.log.info(`fetch workspace ${workspaceDir} from origin`); + await workspaceRepo.fetch('origin'); } return workspaceRepo; } @@ -391,9 +374,8 @@ export class WorkspaceHandler { revision: string ): Promise { const workspaceDir = await this.revisionDir(repositoryUri, revision); - this.log.info(`Create workspace ${workspaceDir} from url ${bareRepo.path()}`); + this.log.info(`clone workspace ${workspaceDir} from url ${bareRepo.path()}`); const parentDir = path.dirname(workspaceDir); - const mainBranchName = path.basename(workspaceDir); // on windows, git clone will failed if parent folder is not exists; await new Promise((resolve, reject) => mkdirp(parentDir, err => { @@ -404,15 +386,7 @@ export class WorkspaceHandler { } }) ); - // Create the worktree and open it as Repository. - const wt = await Worktree.add( - bareRepo, - this.workspaceWorktreeBranchName(mainBranchName), - workspaceDir, - {} - ); - // @ts-ignore - return await Repository.openFromWorktree(wt); + return await Clone.clone(bareRepo.path(), workspaceDir); } private setWorkspaceRevision(workspaceRepo: Repository, headCommit: Commit) { diff --git a/yarn.lock b/yarn.lock index f7d90a7a1c862..15fecbac68240 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1433,10 +1433,10 @@ resolved "https://registry.yarnpkg.com/@elastic/node-crypto/-/node-crypto-0.1.2.tgz#c18ac282f635e88f041cc1555d806e492ca8f3b1" integrity sha1-wYrCgvY16I8EHMFVXYBuSSyo87E= -"@elastic/nodegit@0.25.0-alpha.14": - version "0.25.0-alpha.14" - resolved "https://registry.yarnpkg.com/@elastic/nodegit/-/nodegit-0.25.0-alpha.14.tgz#6ee459a3709064ded4e761ddae9415ccdeb13a49" - integrity sha512-Z5UkqUiC/R4+bp+j/HNy/xgYhcVb2K32YGp8STQq+JV0VI/mbUsc0fWt15NV9oxXkfYIur2oT9jO9EtkDVIjBQ== +"@elastic/nodegit@0.25.0-alpha.12": + version "0.25.0-alpha.12" + resolved "https://registry.yarnpkg.com/@elastic/nodegit/-/nodegit-0.25.0-alpha.12.tgz#6dffdbea640f8b297af75e96f84c802427dff7f7" + integrity sha512-wKTji45igEw3VP2DmgLXpDX3n6WwOy0y4g/Xs385pymn9HWPVyg/UdWLJyXLrl0V//5EDSeqehMqOwTqAQ+qyA== dependencies: fs-extra "^7.0.0" json5 "^2.1.0"