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


TypeScript atom.GitRepository類代碼示例

本文整理匯總了TypeScript中atom.GitRepository的典型用法代碼示例。如果您正苦於以下問題:TypeScript GitRepository類的具體用法?TypeScript GitRepository怎麽用?TypeScript GitRepository使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了GitRepository類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getRepo

export async function getRepo(): Promise<GitRepository | undefined> {
  const activeEditor = atom.workspace.getCenter().getActiveTextEditor();
  if (activeEditor) {
    const path = activeEditor.getPath();
    if (path) {
      let repo = getCachedRepo(path);
      if (repo) return repo;

      const directory = new File(path).getParent();
      repo = await getRepoForDirectory(directory);
      if (repo) return repo;
    }
  }

  const repos: GitRepository[] = (await Promise.all(
    atom.project.getDirectories().map(getRepoForDirectory)
  ).then(results => results.filter(Boolean))) as GitRepository[];

  if (repos.length === 0) return undefined;
  if (repos.length === 1) return repos[0];
  if (repos.length > 1) return chooseRepo(repos);
}
開發者ID:akonwi,項目名稱:git-plus,代碼行數:22,代碼來源:git-es.ts

示例2: git

 push(options: PushOptions = {}): Promise<GitCliResponse> {
   const args = ["push"];
   if (options.setUpstream) args.push("--set-upstream");
   if (options.remote) args.push(options.remote);
   if (options.branch) args.push(options.branch);
   return git(args, { cwd: this.repo.getWorkingDirectory() });
 }
開發者ID:akonwi,項目名稱:git-plus,代碼行數:7,代碼來源:repository.ts

示例3: isPathStaged

 async isPathStaged(path: string): Promise<boolean> {
   const result = await git(["diff", "--cached", "--name-only", path], {
     cwd: this.repo.getWorkingDirectory()
   });
   if (path === this.getWorkingDirectory() && result.output !== "") return true;
   return result.output.includes(this.relativize(path)!);
 }
開發者ID:akonwi,項目名稱:git-plus,代碼行數:7,代碼來源:repository.ts

示例4: getUpstreamBranchFor

 async getUpstreamBranchFor(branch: string): Promise<[string, string] | null> {
   const result = await git(["rev-parse", "--abbrev-ref", `${branch}@{upstream}`], {
     cwd: this.repo.getWorkingDirectory()
   });
   if (result.failed && result.output.includes("fatal: no upstream configured")) return null;
   else return result.output.split("/") as [string, string];
 }
開發者ID:akonwi,項目名稱:git-plus,代碼行數:7,代碼來源:repository.ts

示例5: getRepoForDirectory

export const getRepoForPath = async (path: string) => {
  const repo = getCachedRepo(path);
  if (repo) return repo;

  const stat = fs.statSync(path);
  const directory = new Directory(stat.isFile() ? Path.dirname(path) : path);
  return await getRepoForDirectory(directory);
};
開發者ID:akonwi,項目名稱:git-plus,代碼行數:8,代碼來源:git-es.ts

示例6: getBranchesForRemote

  async getBranchesForRemote(remote: string): Promise<string[]> {
    const { failed, output } = await git(["branch", "-r", "--no-color"], {
      cwd: this.repo.getWorkingDirectory()
    });

    if (failed) return [];

    const branches: string[] = [];
    output.split("\n").forEach(ref => {
      ref = ref.trim();
      if (ref.startsWith(`${remote}/`) && !ref.includes("/HEAD")) {
        branches.push(ref.substring(ref.indexOf("/") + 1));
      }
    });
    return branches;
  }
開發者ID:akonwi,項目名稱:git-plus,代碼行數:16,代碼來源:repository.ts

示例7: getStashes

  async getStashes(): Promise<Stash[]> {
    const { failed, output } = await git(["stash", "list"], {
      cwd: this.repo.getWorkingDirectory()
    });

    if (failed) return [];

    return output
      .split("\n")
      .filter(Boolean)
      .map(stashInfo => {
        const [indexInfo, ...rest] = stashInfo.split(":");
        const indexMatch = indexInfo.match(/\d+/);
        if (!indexMatch) return null;
        return { index: indexMatch[0], label: rest.join().trim(), content: stashInfo };
      })
      .filter(Boolean) as Stash[];
  }
開發者ID:akonwi,項目名稱:git-plus,代碼行數:18,代碼來源:repository.ts

示例8: getRemoteNames

  async getRemoteNames(): Promise<string[]> {
    const { failed, output } = await git(["remote"], { cwd: this.repo.getWorkingDirectory() });

    if (failed) return [];
    return output.split("\n").filter(Boolean);
  }
開發者ID:akonwi,項目名稱:git-plus,代碼行數:6,代碼來源:repository.ts


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