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


TypeScript Repository.init方法代碼示例

本文整理匯總了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();
        }
    }
開發者ID:suiruiw,項目名稱:geeks-diary,代碼行數:8,代碼來源:git.service.spec.ts

示例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
        });
    }
  }
開發者ID:cchampernowne,項目名稱:project-seed,代碼行數:48,代碼來源:repo.ts

示例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();
}
開發者ID:NohSeho,項目名稱:oh-my-github-1,代碼行數:46,代碼來源:nodegit_util.ts

示例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); });
}
開發者ID:tbtimes,項目名稱:lede-cli,代碼行數:72,代碼來源:stage.ts

示例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
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:nodegit-tests.ts

示例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);
});
開發者ID:maxdeviant,項目名稱:orochi,代碼行數:20,代碼來源:orochi-init.ts


注:本文中的nodegit.Repository.init方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。