本文整理汇总了TypeScript中nodegit.Repository类的典型用法代码示例。如果您正苦于以下问题:TypeScript Repository类的具体用法?TypeScript Repository怎么用?TypeScript Repository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Repository类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: openRepository
// Open a new instance of the underlying {NodeGit.Repository}.
//
// By opening multiple connections to the same underlying repository, users
// can safely access the same repository concurrently.
//
// Returns the new {NodeGit.Repository}.
public openRepository (): NodeGitRepository {
if (this.openExactPath) {
return Git.Repository.open(this.openedPath)
} else {
return Git.Repository.openExt(this.openedPath, 0, '')
}
}
示例2: runMigrations
async function runMigrations(fromFolder: string, toFolder: string) {
toFolder = argv.to as string || '.';
if (!fromFolder) {
throw new Error('Must specify --from option when migrating.');
}
fromFolder = resolvePath(fromFolder);
toFolder = resolvePath(toFolder);
if (fromFolder === toFolder) {
logger.info(null, '[migrate] Migration source and destination identical, skipping.');
return;
}
await bootstrapDatabase();
logger.info(null, '[migrate] Migrating from %s to %s...', fromFolder, toFolder);
const fromRepo = await Git.Repository.open(fromFolder);
const toRepo = await Git.Repository.open(toFolder);
const fromCommit = await fromRepo.getHeadCommit();
try {
await toRepo.getCommit(fromCommit.sha());
} catch (err) {
logger.warn(null, '[migrate] Cannot find commit %s in repository %s. Assuming force-push, aborting migrations.', fromCommit.sha(), toFolder);
return;
}
let foundFromCommit = false;
const toCommit = await toRepo.getHeadCommit();
const commits = await new Promise<Commit[]>((resolve, reject) => {
const commitsSince: Commit[] = [];
const emitter = toCommit.history()
.on('end', () => resolve(commitsSince))
.on('error', reject)
.on('commit', (commit: Commit) => {
foundFromCommit = foundFromCommit || commit.sha() === fromCommit.sha();
if (!foundFromCommit) {
commitsSince.push(commit);
}
});
(emitter as any).start();
});
if (!foundFromCommit) {
logger.info(null, '[migrate] Initial commit not found, aborting (this can happen on a force push).');
return;
}
logger.info(null, '[migrate] Found %s commits between %s and %s.', commits.length, fromCommit.sha().substring(0, 7), toCommit.sha().substring(0, 7));
let numScripts = 0;
for (const commit of reverse(commits)) {
const script = scripts.find(filename => commit.sha().startsWith(filename.split('-')[1]));
if (!script) {
continue;
}
logger.info(null, '[migrate] Executing migration script %s for commit %s...', script, commit.sha());
const migrate = require(resolvePath(scriptFolder, script));
await migrate.up();
numScripts++;
}
logger.info(null, '[migrate] %s script%s executed.', numScripts, numScripts === 1 ? '' : 's');
}
示例3: require
(async () => {
try {
const Git = require('nodegit');
const repoRoot = resolve(__dirname, '../../..');
try {
const repo = await Git.Repository.open(repoRoot);
const branch = await repo.getCurrentBranch();
const commit = await repo.getBranchCommit(branch);
this.currentLocalBranch = {
name: branch,
SHA: commit.sha(),
shortSHA: commit.sha().substr(0, 7),
lastCommitTime: new Date(commit.timeMs()),
lastCommitMessage: commit.message(),
lastCommitAuthor: commit.author().name,
};
logger.info(null, '[git] Successfully read git config from %s.', repoRoot);
} catch (err) {
/* istanbul ignore next: we assume node-git is working */
logger.warn(null, '[git] Unable to retrieve git info from %s (%s)', repoRoot, err.message);
}
} catch (err) {
/* istanbul ignore next: we assume node-git is working */
logger.warn(null, '[GitInfo] Error loading library.');
}
})();
示例4: checkoutRemoteBranch
function checkoutRemoteBranch(element) {
let bn;
if (typeof element === "string") {
bn = element;
} else {
bn = element.innerHTML;
}
console.log("1.0 " + bn);
let repos;
Git.Repository.open(repoFullPath)
.then(function(repo) {
repos = repo;
addCommand("git fetch");
addCommand("git checkout -b " + bn);
let cid = remoteName[bn];
console.log("2.0 " + cid);
return Git.Commit.lookup(repo, cid);
})
.then(function(commit) {
console.log("3.0");
return Git.Branch.create(repos, bn, commit, 0);
})
.then(function(code) {
console.log(bn + "PPPPPPP");
repos.mergeBranches(bn, "origin/" + bn)
.then(function() {
refreshAll(repos);
console.log("Pull successful");
});
}, function(err) {
console.log(err);
})
}
示例5: rateLimit
promises.push((async () => {
const dir = path.join('repos', ghRepo.name);
let repo: nodegit.Repository;
if (existsSync(dir)) {
repo = await nodegit.Repository.open(dir);
} else {
await rateLimit(100);
repo = await nodegit.Clone.clone(ghRepo.clone_url, dir, undefined);
}
let skipThisElement = false;
if (opts.branchToFix !== 'master') {
let ref = undefined;
try {
ref = await repo.getBranch(`refs/remotes/origin/${opts.branchToFix}`);
} catch (_) {
skipThisElement = true;
}
if (ref) {
const commit = await repo.getReferenceCommit(ref);
const branch =
await nodegit.Branch.create(repo, opts.branchToFix, commit, 1);
await repo.checkoutBranch(branch);
}
}
if (skipThisElement) {
return undefined;
}
return new ElementRepo({repo, dir, ghRepo, analyzer: null});
})());
示例6: checkoutLocalBranch
function checkoutLocalBranch(element) {
let bn;
let img = "<img"
if (typeof element === "string") {
bn = element;
} else {
bn = element.innerHTML;
}
if (bn.includes(img)) {
bn = bn.substr(0, bn.lastIndexOf(img)) // remove local branch <img> tag from branch name string
if (bn.includes(img)) {
bn = bn.substr(0, bn.lastIndexOf(img)) // remove remote branch <img> tag from branch name string
}
}
console.log("name of branch being checked out: " + bn);
Git.Repository.open(repoFullPath)
.then(function (repo) {
document.getElementById('spinner').style.display = 'block';
addCommand("git checkout " + bn);
repo.checkoutBranch("refs/heads/" + bn)
.then(function () {
refreshAll(repo);
}, function (err) {
console.log("repo.tx, line 271, cannot checkout local branch: " + err);
});
})
}
示例7: getOtherBranches
function getOtherBranches() {
let list;
let repos;
Git.Repository.open(repoFullPath)
.then(function(repo) {
repos = repo;
return repo.getReferenceNames(Git.Reference.TYPE.LISTALL);
})
.then(function(branchList) {
clearMergeElement();
list = branchList;
})
.then(function() {
return repos.getCurrentBranch()
})
.then(function(ref) {
let name = ref.name().split("/");
console.log("&&&&&&&");
clearBranchElement();
for (let i = 0; i < list.length; i++) {
let bp = list[i].split("/");
if (bp[1] !== "remotes" && bp[bp.length - 1] !== name[name.length - 1]) {
displayBranch(bp[bp.length - 1], "merge-dropdown", "mergeLocalBranches(this)");
}
}
})
}
示例8: checkoutGhPagesBranch
export async function checkoutGhPagesBranch(path: string, user: string) {
let repo: NodeGitRepository = undefined;
/** initialize repository if not exist */
try {
repo = await nodegit.Repository.open(path);
} catch (error) {
Log.info("git init");
repo = await nodegit.Repository.init(path, 0);
}
let branch: NodeGitBranch = undefined;
/** do initial commit if not exist */
try {
branch = await repo.getCurrentBranch();
} catch (error) {
await addAllAndCommit(path, user, "initial commit", true);
repo = await nodegit.Repository.open(path);
branch = await repo.getCurrentBranch();
}
/** lookup gh-pages branch and create it if not exists */
try {
let ghPagesBranch = await repo.getBranch("gh-pages");
} catch (error) {
Log.info("git branch gh-pages HEAD");
let headCommit = await repo.getHeadCommit();
await repo.createBranch("gh-pages", headCommit, 0, repo.defaultSignature(), "message");
}
/** checkout gh-pages */
let branchName = branch.name();
if (!branchName.endsWith("/gh-pages")) {
Log.info("git checkout gh-pages");
repo = await nodegit.Repository.open(path);
return await repo.checkoutBranch("gh-pages", {
checkoutStrategy: nodegit.Checkout.STRATEGY.SAFE | nodegit.Checkout.STRATEGY.RECREATE_MISSING
});
}
return await Promise.resolve();
}
示例9: makeTmpPath
async function makeTmpPath(createGit: boolean = false): Promise<void> {
await fse.ensureDir(tmpPath);
if (createGit) {
const repo = await _git.Repository.init(tmpPath, 0);
repo.free();
}
}
示例10: ElementRepo
promises.push(Promise.resolve().then(() => {
const dir = path.join('repos', ghRepo.name);
let repoPromise: Promise<nodegit.Repository>;
if (existsSync(dir)) {
repoPromise = nodegit.Repository.open(dir);
} else {
repoPromise = rateLimit(100).then(
() => nodegit.Clone.clone(ghRepo.clone_url, dir, null));
}
return repoPromise.then((repo) =>
new ElementRepo({repo, dir, ghRepo, analyzer: null})
);
}));