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


TypeScript nodegit.Repository類代碼示例

本文整理匯總了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, '')
   }
 }
開發者ID:github,項目名稱:ohnogit,代碼行數:13,代碼來源:repository.ts

示例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');
}
開發者ID:freezy,項目名稱:node-vpdb,代碼行數:57,代碼來源:migrate.ts

示例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.');
			}
		})();
開發者ID:freezy,項目名稱:node-vpdb,代碼行數:27,代碼來源:gitinfo.ts

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

示例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});
 })());
開發者ID:TimvdLippe,項目名稱:tedium,代碼行數:29,代碼來源:tedium.ts

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

示例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)");
      }
    }
  })

}
開發者ID:ElliotWhiley,項目名稱:VisualGit,代碼行數:28,代碼來源:repo.ts

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

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

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


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