• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript nodegit.Repository类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@elastic/nodegit.Repository的典型用法代码示例。如果您正苦于以下问题:TypeScript Repository类的具体用法?TypeScript Repository怎么用?TypeScript Repository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Repository类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: getCommit

 public async getCommit(repo: Repository, revision: string): Promise<Commit> {
   if (revision.toUpperCase() === 'HEAD') {
     return await repo.getHeadCommit();
   }
   // branches and tags
   const refs = [`refs/remotes/origin/${revision}`, `refs/tags/${revision}`];
   const commit = await this.findCommitByRefs(repo, refs);
   if (commit === null) {
     return (await checkExists(
       () => this.findCommit(repo, revision),
       `revision or branch ${revision} not found in ${repo.path()}`
     )) as Commit;
   }
   return commit;
 }
开发者ID:elastic,项目名称:kibana,代码行数:15,代码来源:git_operations.ts


示例2: prepareProject

  async function prepareProject(repoPath: string) {
    mkdirp.sync(repoPath);
    const repo = await Git.Repository.init(repoPath, 0);
    const content = '';
    fs.writeFileSync(path.join(repo.workdir(), '1'), content, 'utf8');
    const subFolder = 'src';
    fs.mkdirSync(path.join(repo.workdir(), subFolder));
    fs.writeFileSync(path.join(repo.workdir(), 'src/2'), content, 'utf8');
    fs.writeFileSync(path.join(repo.workdir(), 'src/3'), content, 'utf8');

    const index = await repo.refreshIndex();
    await index.addByPath('1');
    await index.addByPath('src/2');
    await index.addByPath('src/3');
    index.write();
    const treeId = await index.writeTree();
    const committer = Git.Signature.create('tester', '[email protected]', Date.now() / 1000, 60);
    const commit = await repo.createCommit(
      'HEAD',
      committer,
      committer,
      'commit for test',
      treeId,
      []
    );
    // eslint-disable-next-line no-console
    console.log(`created commit ${commit.tostrS()}`);
    return repo;
  }
开发者ID:elastic,项目名称:kibana,代码行数:29,代码来源:git_operations.ts


示例3: it

  it('should update if a worktree is not the newest', async () => {
    const lspservice = mockLspService();
    try {
      const revision = 'master';
      // send a dummy request to open a workspace;
      const response = await sendHoverRequest(lspservice, revision);
      assert.ok(response);
      const workspacePath = path.resolve(serverOptions.workspacePath, repoUri, revision);
      const workspaceRepo = await Git.Repository.open(workspacePath);
      // workspace is newest now
      assert.strictEqual((await workspaceRepo.getHeadCommit()).sha(), secondCommitSha);
      const firstCommit = await workspaceRepo.getCommit(firstCommitSha);
      // reset workspace to an older one
      // @ts-ignore
      await Git.Reset.reset(workspaceRepo, firstCommit, Git.Reset.TYPE.HARD, {});
      assert.strictEqual((await workspaceRepo.getHeadCommit()).sha(), firstCommitSha);

      // send a request again;
      await sendHoverRequest(lspservice, revision);
      // workspace_handler should update workspace to the newest one
      assert.strictEqual((await workspaceRepo.getHeadCommit()).sha(), secondCommitSha);
      return;
    } finally {
      await lspservice.shutdown();
    }
    // @ts-ignore
  }).timeout(10000);
开发者ID:elastic,项目名称:kibana,代码行数:27,代码来源:lsp_service.ts


示例4: getDefaultBranch

export async function getDefaultBranch(path: string): Promise<string> {
  const repo = await Repository.open(path);
  const ref = await repo.getReference(HEAD);
  const name = ref.name();
  if (name.startsWith(REFS_HEADS)) {
    return name.substr(REFS_HEADS.length);
  }
  return name;
}
开发者ID:elastic,项目名称:kibana,代码行数:9,代码来源:git_operations.ts


示例5: getOriginCode

 private async getOriginCode(commit: Commit, repo: Repository, path: string) {
   for (const oid of commit.parents()) {
     const parentCommit = await repo.getCommit(oid);
     if (parentCommit) {
       const entry = await parentCommit.getEntry(path);
       if (entry) {
         return (await entry.getBlob()).content().toString('utf8');
       }
     }
   }
   return '';
 }
开发者ID:elastic,项目名称:kibana,代码行数:12,代码来源:git_operations.ts


示例6: findCommitByRefs

 private async findCommitByRefs(repo: Repository, refs: string[]): Promise<Commit | null> {
   if (refs.length === 0) {
     return null;
   }
   const [ref, ...rest] = refs;
   try {
     return await repo.getReferenceCommit(ref);
   } catch (e) {
     if (e.errno === NodeGitError.CODE.ENOTFOUND) {
       return await this.findCommitByRefs(repo, rest);
     } else {
       throw e;
     }
   }
 }
开发者ID:elastic,项目名称:kibana,代码行数:15,代码来源:git_operations.ts


示例7: findCommit

 private async findCommit(repo: Repository, revision: string): Promise<Commit | null> {
   try {
     const obj = await Object.lookupPrefix(
       repo,
       Oid.fromString(revision),
       revision.length,
       Object.TYPE.COMMIT
     );
     if (obj) {
       return repo.getCommit(obj.id());
     }
     return null;
   } catch (e) {
     return null;
   }
 }
开发者ID:elastic,项目名称:kibana,代码行数:16,代码来源:git_operations.ts


示例8: doUpdate

 public async doUpdate(uri: string, key?: string): Promise<UpdateWorkerResult> {
   const localPath = RepositoryUtils.repositoryLocalPath(this.repoVolPath, uri);
   try {
     const repo = await Git.Repository.open(localPath);
     const cbs: RemoteCallbacks = {
       credentials: this.credentialFunc(key),
     };
     // Ignore cert check on testing environment.
     if (!this.enableGitCertCheck) {
       cbs.certificateCheck = () => {
         // Ignore cert check failures.
         return 0;
       };
     }
     await repo.fetchAll({
       callbacks: cbs,
     });
     // TODO(mengwei): deal with the case when the default branch has changed.
     const currentBranch = await repo.getCurrentBranch();
     const currentBranchName = currentBranch.shorthand();
     const originBranchName = `origin/${currentBranchName}`;
     const originRef = await repo.getReference(originBranchName);
     const headRef = await repo.getReference(currentBranchName);
     if (!originRef.target().equal(headRef.target())) {
       await headRef.setTarget(originRef.target(), 'update');
     }
     const headCommit = await repo.getHeadCommit();
     this.log.debug(`Update repository to revision ${headCommit.sha()}`);
     return {
       uri,
       branch: currentBranchName,
       revision: headCommit.sha(),
     };
   } catch (error) {
     if (error.message && error.message.startsWith(SSH_AUTH_ERROR.message)) {
       throw SSH_AUTH_ERROR;
     } else {
       const msg = `update repository ${uri} error: ${error}`;
       this.log.error(msg);
       throw new Error(msg);
     }
   }
 }
开发者ID:elastic,项目名称:kibana,代码行数:43,代码来源:repository_service.ts


示例9: prepareProject

  async function prepareProject(repoPath: string) {
    mkdirp.sync(repoPath);
    const repo = await Git.Repository.init(repoPath, 0);
    const content = 'console.log("test")';
    const subFolder = 'src';
    fs.mkdirSync(path.join(repo.workdir(), subFolder));
    fs.writeFileSync(path.join(repo.workdir(), 'src/app.ts'), content, 'utf8');

    const index = await repo.refreshIndex();
    await index.addByPath('src/app.ts');
    index.write();
    const treeId = await index.writeTree();
    const committer = Git.Signature.create('tester', '[email protected]', Date.now() / 1000, 60);
    const commit = await repo.createCommit(
      'HEAD',
      committer,
      committer,
      'commit for test',
      treeId,
      []
    );
    return { repo, commit };
  }
开发者ID:elastic,项目名称:kibana,代码行数:23,代码来源:workspace_handler.ts


示例10: prepareProject

  async function prepareProject(repoPath: string) {
    mkdirp.sync(repoPath);
    const repo = await Git.Repository.init(repoPath, 0);
    const helloContent = "console.log('hello world');";
    fs.writeFileSync(path.join(repo.workdir(), filename), helloContent, 'utf8');

    let index = await repo.refreshIndex();
    await index.addByPath(filename);
    index.write();
    const treeId = await index.writeTree();
    const committer = Git.Signature.create('tester', '[email protected]', Date.now() / 1000, 60);
    const commit = await repo.createCommit(
      'HEAD',
      committer,
      committer,
      'commit for test',
      treeId,
      []
    );
    firstCommitSha = commit.tostrS();
    fs.writeFileSync(path.join(repo.workdir(), 'package.json'), packagejson, 'utf8');
    index = await repo.refreshIndex();
    await index.addByPath('package.json');
    index.write();
    const treeId2 = await index.writeTree();
    const commit2 = await repo.createCommit(
      'HEAD',
      committer,
      committer,
      'commit2 for test',
      treeId2,
      [commit]
    );
    secondCommitSha = commit2.tostrS();

    return repo;
  }
开发者ID:elastic,项目名称:kibana,代码行数:37,代码来源:lsp_service.ts



注:本文中的@elastic/nodegit.Repository类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript nodegit.Tree类代码示例发布时间:2022-05-28
下一篇:
TypeScript nodegit.Clone类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap