mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
This commit is contained in:
parent
b7a98a03d1
commit
fcc2520822
3 changed files with 36 additions and 10 deletions
|
@ -169,7 +169,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.12",
|
||||
"@elastic/nodegit": "0.25.0-alpha.19",
|
||||
"@elastic/numeral": "2.3.3",
|
||||
"@kbn/babel-preset": "1.0.0",
|
||||
"@kbn/elastic-idx": "1.0.0",
|
||||
|
|
|
@ -4,7 +4,15 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { Clone, Commit, Error as GitError, Repository, Reset, TreeEntry } from '@elastic/nodegit';
|
||||
import {
|
||||
Commit,
|
||||
Error as GitError,
|
||||
Repository,
|
||||
Reset,
|
||||
TreeEntry,
|
||||
// @ts-ignore
|
||||
Worktree,
|
||||
} from '@elastic/nodegit';
|
||||
import Boom from 'boom';
|
||||
import del from 'del';
|
||||
import fs from 'fs';
|
||||
|
@ -353,6 +361,10 @@ export class WorkspaceHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private workspaceWorktreeBranchName(repoName: string): string {
|
||||
return `workspace-${repoName}`;
|
||||
}
|
||||
|
||||
private async updateWorkspace(
|
||||
repositoryUri: string,
|
||||
revision: string,
|
||||
|
@ -362,8 +374,13 @@ export class WorkspaceHandler {
|
|||
const workspaceRepo = await Repository.open(workspaceDir);
|
||||
const workspaceHead = await workspaceRepo.getHeadCommit();
|
||||
if (workspaceHead.sha() !== targetCommit.sha()) {
|
||||
this.log.info(`fetch workspace ${workspaceDir} from origin`);
|
||||
await workspaceRepo.fetch('origin');
|
||||
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.`);
|
||||
}
|
||||
}
|
||||
return workspaceRepo;
|
||||
}
|
||||
|
@ -374,8 +391,9 @@ export class WorkspaceHandler {
|
|||
revision: string
|
||||
): Promise<Repository> {
|
||||
const workspaceDir = await this.revisionDir(repositoryUri, revision);
|
||||
this.log.info(`clone workspace ${workspaceDir} from url ${bareRepo.path()}`);
|
||||
this.log.info(`Create 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 => {
|
||||
|
@ -386,7 +404,15 @@ export class WorkspaceHandler {
|
|||
}
|
||||
})
|
||||
);
|
||||
return await Clone.clone(bareRepo.path(), workspaceDir);
|
||||
// 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);
|
||||
}
|
||||
|
||||
private setWorkspaceRevision(workspaceRepo: Repository, headCommit: Commit) {
|
||||
|
|
|
@ -1443,10 +1443,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.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==
|
||||
"@elastic/nodegit@0.25.0-alpha.19":
|
||||
version "0.25.0-alpha.19"
|
||||
resolved "https://registry.yarnpkg.com/@elastic/nodegit/-/nodegit-0.25.0-alpha.19.tgz#a05a712dedbdbd7fe649cb970eb5677c5ec4ada8"
|
||||
integrity sha512-fOG7tXkf8wmZEVMld+tkZtS3BRsUlrh95sRNUglHDd0G3g+ow9YDjV3dFHlLST0pTWirKyJuxrow2KgpLoWplA==
|
||||
dependencies:
|
||||
fs-extra "^7.0.0"
|
||||
json5 "^2.1.0"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue