當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript nodegit.Repository類代碼示例

本文整理匯總了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', 'test@test.com', 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', 'test@test.com', 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', 'test@test.com', 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;未經允許,請勿轉載。