本文整理汇总了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;
}
示例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;
}
示例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);
示例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;
}
示例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 '';
}
示例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;
}
}
}
示例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;
}
}
示例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);
}
}
}
示例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 };
}
示例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;
}