当前位置: 首页>>代码示例>>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;未经允许,请勿转载。