本文整理汇总了TypeScript中nodegit.Repository.init方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Repository.init方法的具体用法?TypeScript Repository.init怎么用?TypeScript Repository.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nodegit.Repository
的用法示例。
在下文中一共展示了Repository.init方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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();
}
}
示例2: createLocalRepository
function createLocalRepository() {
//console.log("createLocalRepo")
if (document.getElementById("repoCreate").value == null || document.getElementById("repoCreate").value == "") {
document.getElementById("dirPickerCreateLocal").click();
let localPath = document.getElementById("dirPickerCreateLocal").files[0].webkitRelativePath;
let fullLocalPath = document.getElementById("dirPickerCreateLocal").files[0].path;
document.getElementById("repoCreate").value = fullLocalPath;
document.getElementById("repoCreate").text = fullLocalPath;
} else {
let localPath = document.getElementById("repoCreate").value;
let fullLocalPath;
if (!require('path').isAbsolute(localPath)) {
updateModalText('The filepath is not valid. For OSX and Ubuntu the filepath should start with /, for Windows C:\\\\')
return
} else {
if (checkFile.existsSync(localPath)) {
fullLocalPath = localPath;
} else {
checkFile.mkdirSync(localPath);
fullLocalPath = localPath;
}
}
}
//console.log("pre-git check")
//console.log("fullLocalPath is " + fullLocalPath)
//console.log(require("path").join(fullLocalPath,".git"));
if (checkFile.existsSync(require("path").join(fullLocalPath, ".git"))) {
//console.log("Is git repository already")
updateModalText("This folder is already a git repository. Please try to open it instead.");
} else {
displayModal("creating repository at " + require("path").join(fullLocalPath, ".git"));
Git.Repository.init(fullLocalPath, 0).then(function (repository) {
repoFullPath = fullLocalPath;
repoLocalPath = localPath;
refreshAll(repository);
//console.log("Repo successfully created");
updateModalText("Repository successfully created");
document.getElementById("repoCreate").value = "";
document.getElementById("dirPickerCreateLocal").value = null;
switchToMainPanel();
},
function (err) {
updateModalText("Creating Failed - " + err);
//console.log("repo.ts, line 131, cannot open repository: "+err); // TODO show error on screen
});
}
}
示例3: 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();
}
示例4: stageCommand
export async function stageCommand(config: Config, args) {
const logger = config.logger;
const path = args["p"] || args["path"] || process.cwd();
const workingDir = await searchForProjectDir(path);
const projectName = await getProjectName(workingDir);
const remoteUrl = await Git.Repository.open(workingDir).then(function(repository) {
return repository.getRemote("origin").then(function(remote) {
return remote.url();
});
});
const serveUrl = "https://tbtimes.github.io/" + projectName + "/";
let servePath = join(workingDir, config.caches.DEPLOY_DIR, projectName);
const projectDirs = await glob(`*/`, {cwd: servePath});
const servePathGit = servePath + "/.git/";
if (existsSync(servePathGit)) {
logger.info("Deleting existing .git directory.")
rmrf.sync(servePathGit);
}
let repo, index, oid;
const token = args["t"] || args["token"] || config.GH_TOKEN || process.env.GH_TOKEN;
if (!token)
logger.error(`Must specify a token to access github.`) && process.exit(1);
const pushOpts = {
callbacks: {
credentials: function () {
return Git.Cred.userpassPlaintextNew(token, "x-oauth-basic");
}
}
};
if (process.platform === "darwin") {
pushOpts.callbacks.certificateCheck = function () { return 1; };
}
const signature = Git.Signature.now("newsroom-user", "ejmurra2@gmail.com");
await Git.Repository.init(servePath, 0)
.then(function(repository) {
repo = repository;
return repo.refreshIndex().then(function(indexResult) {
index = indexResult;
return index.addAll()
.then(function() {
return index.write();
})
.then(function() {
return index.writeTree();
});
});
})
.then(function(oidResult) {
oid = oidResult;
return repo.createCommit("HEAD", signature, signature, "lede stage", oid);
})
.then(function(o) {
return repo.createBranch("gh-pages", o);
})
.then(function() {
return repo.checkoutBranch("gh-pages");
})
.then(function() {
return Git.Remote.create(repo, "origin", remoteUrl).then(function(remote) {
logger.info("Pushing to GitHub.");
return remote.push("+refs/heads/gh-pages:refs/heads/gh-pages", pushOpts)
.then(function() {
return projectDirs.map(dir=> logger.info(dir.slice(0,-1) + " served at " + serveUrl + dir));
})
})
}, function(err) { logger.error(err); });
}
示例5:
import * as Git from 'nodegit';
Git.Repository.discover("startPath", 1, "ceilingDirs").then((string) => {
// Use string
});
Git.Repository.init("path", 0).then((repository) => {
// Use repository
});
const repo = new Git.Repository();
const id = new Git.Oid();
const ref = new Git.Reference();
const tree = new Git.Tree();
// AnnotatedCommit Tests
Git.AnnotatedCommit.fromFetchhead(repo, "branch_name", "remote_url", id).then((annotatedCommit) => {
// Use annotatedCommit
});
Git.AnnotatedCommit.fromRef(repo, ref).then((annotatedCommit) => {
// Use annotatedCommit
});
Git.AnnotatedCommit.fromRevspec(repo, "revspec").then((annotatedCommit) => {
// Use annotatedCommit
});
Git.AnnotatedCommit.lookup(repo, id).then((annotatedCommit) => {
// Use annotatedCommit
示例6: require
import * as cli from 'commander';
import * as path from 'path';
const NodeGit = require('nodegit');
cli
.usage('[dir]')
.parse(process.argv);
let directory = cli.args[0];
console.log(directory)
let repositoryPath = path.resolve(directory);
let isBare = 0;
NodeGit.Repository.init(repositoryPath, isBare).then((repository: any) => {
console.log('done');
}).catch((err: any) => {
console.log(err);
});